discard ExprStatNodes with constant expressions
authorStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Dec 2013 10:15:59 +0000 (11:15 +0100)
committerStefan Behnel <stefan_ml@behnel.de>
Sun, 8 Dec 2013 10:15:59 +0000 (11:15 +0100)
Cython/Compiler/Optimize.py

index 27a10d9..d1a53d6 100644 (file)
@@ -3402,6 +3402,13 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
                 return node
         return None
 
+    def visit_ExprStatNode(self, node):
+        self.visitchildren(node)
+        # drop unused constant expressions
+        if node.expr.has_constant_result():
+            return None
+        return node
+
     # in the future, other nodes can have their own handler method here
     # that can replace them with a constant result node