fix final optimisations for calls inside of assignments
authorStefan Behnel <scoder@users.berlios.de>
Fri, 28 Nov 2008 09:11:54 +0000 (10:11 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Fri, 28 Nov 2008 09:11:54 +0000 (10:11 +0100)
Cython/Compiler/Optimize.py

index c587bbd598376efaffea490a8e5ec48b0ca8206f..c47a1989bddf1bbb8c960b71b2366b2baa80b896 100644 (file)
@@ -350,6 +350,10 @@ class FinalOptimizePhase(Visitor.CythonTransform):
         - isinstance -> typecheck for cdef types
     """
     def visit_SingleAssignmentNode(self, node):
+        """Avoid redundant initialisation of local variables before their
+        first assignment.
+        """
+        self.visitchildren(node)
         if node.first:
             lhs = node.lhs
             lhs.lhs_of_first_assignment = True
@@ -360,6 +364,9 @@ class FinalOptimizePhase(Visitor.CythonTransform):
         return node
 
     def visit_SimpleCallNode(self, node):
+        """Replace generic calls to isinstance(x, type) by a more efficient
+        type check.
+        """
         self.visitchildren(node)
         if node.function.type.is_cfunction and isinstance(node.function, ExprNodes.NameNode):
             if node.function.name == 'isinstance':