Commits

Andriy Kornatskyy  committed 292983d

Minor refactoring related to optimizing performance

  • Participants
  • Parent commits f769a6a

Comments (0)

Files changed (2)

File src/wheezy/html/factory.py

         self.builders = {}
 
     def __getattr__(self, name):
-        try:
+        if name in self.builders:
             return self.builders[name]
-        except KeyError:
+        else:
             value = getattr(self.model, name)
             builder = WidgetBuilder(name, value, self.errors.get(name, None))
             self.builders[name] = builder

File src/wheezy/html/markup.py

             >>> Tag('input')(id='name', value='abc')
             <input id="name" value="abc" />
         """
-        parts = []
-        append = parts.append
-        append('<' + self.name)
-        if self.attrs:
-            for name, value in iteritems(self.attrs):
-                append(' ' + name.rstrip('_') +
-                        '="' + value + '"')
-        if self.inner is not None:
-            append('>' + converter(self.inner) +
-                    '</' + self.name + '>')
+        name = self.name
+        attrs = self.attrs
+        if attrs:
+            t = '<' + name + ' ' + ' '.join(
+                    [k.rstrip('_') + '="' + attrs[k] + '"'
+                        for k in attrs])
         else:
-            append(' />')
-        return ''.join(parts)
+            t = '<' + name
+        inner = self.inner
+        if inner is not None:
+            return t + '>' + converter(inner) + '</' + name + '>'
+        else:
+            return t + ' />'
+        # 0.442
+        #parts = []
+        #append = parts.append
+        #append('<' + self.name)
+        #attrs = self.attrs
+        #if attrs:
+        #    parts.extend([' ' + name.rstrip('_') + '="' + attrs[name] + '"'
+        #        for name in attrs])
+        #    #for name, value in iteritems(self.attrs):
+        #    #    append(' ' + name.rstrip('_') +
+        #    #            '="' + value + '"')
+        #if self.inner is not None:
+        #    append('>' + converter(self.inner) +
+        #            '</' + self.name + '>')
+        #else:
+        #    append(' />')
+        #return ''.join(parts)
 
 
 class Fragment(object):