[Checkins] SVN: z3c.pt/trunk/ Optimized 'is None' handling in Write clause. Most common case is that we have unicode, which means we don't have a None value. If we do have a None value, we don't want to write out anything at all.

Hanno Schlichting plone at hannosch.info
Sat Jun 14 13:24:19 EDT 2008


Log message for revision 87395:
  Optimized 'is None' handling in Write clause. Most common case is that we have unicode, which means we don't have a None value. If we do have a None value, we don't want to write out anything at all.
  

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

-=-
Modified: z3c.pt/trunk/docs/HISTORY.txt
===================================================================
--- z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 17:11:33 UTC (rev 87394)
+++ z3c.pt/trunk/docs/HISTORY.txt	2008-06-14 17:24:19 UTC (rev 87395)
@@ -4,6 +4,8 @@
 Version 0.8.x
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+- Optimized 'is None' handling in Write clause.
+
 - Slightly refactored benchmark tests and added tests for the file variants.
 
 - In debug mode the actual source code for file templates is written out to

Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-06-14 17:11:33 UTC (rev 87394)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-06-14 17:24:19 UTC (rev 87395)
@@ -664,14 +664,13 @@
             expr = temp
 
         stream.write("_urf = %s" % expr)
-        stream.write("if _urf is None: _urf = ''")
 
         if unicode_required_flag:
             stream.write("if isinstance(_urf, unicode):")
             stream.indent()
             stream.write("_out.write(_urf.encode('utf-8'))")
             stream.outdent()
-            stream.write("else:")
+            stream.write("elif _urf is not None:")
             stream.indent()
             if self.structure:
                 stream.write("_out.write(str(_urf))")
@@ -679,11 +678,14 @@
                 stream.write("_out.write(_escape(str(_urf)))")
             stream.outdent()
         else:
+            stream.write("if _urf is not None:")
+            stream.indent()
             if self.structure:
                 stream.write("_out.write(str(_urf))")
             else:
                 stream.write("_out.write(_escape(str(_urf)))")
-            
+            stream.outdent()
+
     def end(self, stream):
         if self.assign:
             self.assign.end(stream)



More information about the Checkins mailing list