[Checkins] SVN: z3c.pt/trunk/src/z3c/pt/clauses.py Slight optimization of conditions.

Malthe Borch mborch at gmail.com
Wed Sep 10 16:14:31 EDT 2008


Log message for revision 91040:
  Slight optimization of conditions.

Changed:
  U   z3c.pt/trunk/src/z3c/pt/clauses.py

-=-
Modified: z3c.pt/trunk/src/z3c/pt/clauses.py
===================================================================
--- z3c.pt/trunk/src/z3c/pt/clauses.py	2008-09-10 20:08:02 UTC (rev 91039)
+++ z3c.pt/trunk/src/z3c/pt/clauses.py	2008-09-10 20:14:30 UTC (rev 91040)
@@ -506,17 +506,25 @@
             # whether we're dealing with unicode strings or not,
             # before writing out the attribute
             if stream.encoding is not None:
-                for t in (temp, temp2):
-                    stream.write("if isinstance(%s, unicode):" % t)
-                    stream.indent()
-                    stream.write("%s = %s.encode('%s')" % (t, t, stream.encoding))
-                    stream.outdent()
+                # attribute name
+                stream.write("if isinstance(%s, unicode):" % temp)
+                stream.indent()
+                stream.write("%s = %s.encode('%s')" % (temp, temp, stream.encoding))
+                stream.outdent()
 
-                # make sure this is a string
-                stream.write("if not isinstance(%s, (str, unicode)):" % temp2)
+                # attribute expression
+                stream.write("if isinstance(%s, unicode):" % temp2)
                 stream.indent()
-                stream.write("%s = str(%s)" % (temp2, temp2))
+                stream.write("%s = %s.encode('%s')" % (temp2, temp2, stream.encoding))
                 stream.outdent()
+                stream.write("elif not isinstance(%s, str):" % temp2)
+            else:
+                stream.write("if not isinstance(%s, (str, unicode)):" % temp2)
+
+            # make sure this is a string
+            stream.indent()
+            stream.write("%s = str(%s)" % (temp2, temp2))
+            stream.outdent()
                 
             # escape expression
             stream.escape(temp2)



More information about the Checkins mailing list