[Checkins] SVN: z3c.pt/trunk/ Optimized 'is None' handling in Tag clause similar to the Write clause.

Hanno Schlichting plone at hannosch.info
Sat Jun 14 15:27:54 EDT 2008


Log message for revision 87403:
  Optimized 'is None' handling in Tag clause similar to the Write clause.
  
  The Python syntax is back at a 10x factor of being faster.
  

Changed:
  U   z3c.pt/trunk/benchmark/benchmark/tests.py
  U   z3c.pt/trunk/docs/HISTORY.txt
  U   z3c.pt/trunk/src/z3c/pt/clauses.py

-=-
Modified: z3c.pt/trunk/benchmark/benchmark/tests.py
===================================================================
--- z3c.pt/trunk/benchmark/benchmark/tests.py	2008-06-14 18:52:50 UTC (rev 87402)
+++ z3c.pt/trunk/benchmark/benchmark/tests.py	2008-06-14 19:27:53 UTC (rev 87403)
@@ -171,6 +171,17 @@
         print "zope.pagetemplate: %.2f" % t_zope
         print "                   %.2fX" % (t_zope/t_z3c)
 
+        print "--------------------------"
+        print " Second rendering"
+        print "--------------------------"
+
+        t_z3c = timing(z3cfile.render, table=table)
+        t_zope = timing(zopefile, table=table)
+
+        print "z3c.pt:            %.2f" % t_z3c
+        print "zope.pagetemplate: %.2f" % t_zope
+        print "                   %.2fX" % (t_zope/t_z3c)
+
 # Use a custom context to add real i18n lookup
 
 from zope.i18n import translate

Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 18:52:50 UTC (rev 87402)
+++ z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 19:27:53 UTC (rev 87403)
@@ -4,6 +4,8 @@
 Version 0.8.x
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Optimized 'is None' handling in Tag clause similar to the Write clause.
+
 - Made the _out.write method directly available as _write in all scopes, so
   we avoid the method lookup call each time.
 

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-06-14 18:52:50 UTC (rev 87402)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-06-14 19:27:53 UTC (rev 87403)
@@ -486,32 +486,28 @@
             assign = Assign(value)
             assign.begin(stream, temp)
             
-            # only include attribute if value is non-trivial
-            stream.write("if %s is not None:" % temp)
-            stream.indent()
-
-            #if not value.options.get('nocall'):
-            #    # if callable, evaluate method
-            #    stream.write("if callable(%s): %s = %s()" % (temp, temp, temp))
-
             if unicode_required_flag:
                 stream.write("if isinstance(%s, unicode):" % temp)
                 stream.indent()
                 stream.write("%s = %s.encode('utf-8')" % (temp, temp))
+                stream.write("_write(' %s=\"'+_escape(%s, \"\\\"\")+'\"')" %
+                             (attribute, temp))
                 stream.outdent()
-                stream.write("else:")
+                stream.write("elif %s is not None:" % temp)
                 stream.indent()
                 stream.write("%s = str(%s)" % (temp, temp))
+                stream.write("_write(' %s=\"'+_escape(%s, \"\\\"\")+'\"')" %
+                             (attribute, temp))
                 stream.outdent()
             else:
+                stream.write("if %s is not None:" % temp)
+                stream.indent()
                 stream.write("%s = str(%s)" % (temp, temp))
-                
-            stream.write("_write(' %s=\"' + _escape(%s, \"\\\"\"))" %
-                         (attribute, temp))
-            stream.out('"')
-            
+                stream.write("_write(' %s=\"'+_escape(%s, \"\\\"\")+'\"')" %
+                             (attribute, temp))
+                stream.outdent()
+
             assign.end(stream)
-            stream.outdent()
 
         stream.restore()
 



More information about the Checkins mailing list