drop redundant C->Py->C coercions after optimisations
authorStefan Behnel <scoder@users.berlios.de>
Sun, 21 Mar 2010 19:50:08 +0000 (20:50 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 21 Mar 2010 19:50:08 +0000 (20:50 +0100)
Cython/Compiler/Optimize.py

index 5d587160a5a9c7a3417a01ba0636f9bc75105ffc..85a405a8797e904d3d7e8d2f782bb55a28f60557 100644 (file)
@@ -962,6 +962,11 @@ class OptimizeBuiltinCalls(Visitor.EnvTransform):
                 return arg
             else:
                 return arg.coerce_to(node.type, self.env_stack[-1])
+        if isinstance(arg, ExprNodes.CoerceToPyTypeNode):
+            if arg.type is PyrexTypes.py_object_type:
+                if node.type.assignable_from(arg.arg.type):
+                    # completely redundant C->Py->C coercion
+                    return arg.arg.coerce_to(node.type, self.env_stack[-1])
         if not isinstance(arg, ExprNodes.SimpleCallNode):
             return node
         if not (node.type.is_int or node.type.is_float):