From b80966c6d9a4aa88ea8f972892dc971339afe302 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sat, 29 Dec 2012 17:25:51 +0100 Subject: [PATCH] fix evaluation of assignment order when considering DefNode calls for inlining --- Cython/Compiler/Optimize.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Cython/Compiler/Optimize.py b/Cython/Compiler/Optimize.py index 815aeb1..4c60773 100644 --- a/Cython/Compiler/Optimize.py +++ b/Cython/Compiler/Optimize.py @@ -1660,18 +1660,25 @@ class EarlyReplaceBuiltinCalls(Visitor.EnvTransform): class InlineDefNodeCalls(Visitor.EnvTransform): visit_Node = Visitor.VisitorTransform.recurse_to_children + def get_constant_value_node(self, name_node): + if not name_node.cf_state or not name_node.cf_state.is_single: + # no single assignment in the current scope + return None + entry = self.current_env().lookup(name_node.name) + if not entry or (not entry.cf_assignments + or len(entry.cf_assignments) != 1): + # not just a single assignment in all closures + return None + return name_node.cf_state.one().rhs + def visit_SimpleCallNode(self, node): self.visitchildren(node) if not self.current_directives.get('optimize.inline_defnode_calls'): return node function_name = node.function - if not function_name.is_name or function_name.cf_state is None: - return node - entry = self.current_env().lookup(function_name.name) - if not entry or (not entry.cf_assignments - or len(entry.cf_assignments) != 1): + if not function_name.is_name: return node - function = entry.cf_assignments[0].rhs + function = self.get_constant_value_node(function_name) if not isinstance(function, ExprNodes.PyCFunctionNode): return node inlined = ExprNodes.InlinedDefNodeCallNode( -- 2.7.4