Commit 784722da authored by Stefan Behnel's avatar Stefan Behnel

Re-enable method unpacking inside of the module init function if the call...

Re-enable method unpacking inside of the module init function if the call occurs inside of a loop (probably still worth it there).
See #2102.
parent 63cd3bbb
...@@ -4596,6 +4596,8 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin): ...@@ -4596,6 +4596,8 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin):
- eliminate useless string formatting steps - eliminate useless string formatting steps
- replace Python function calls that look like method calls by a faster PyMethodCallNode - replace Python function calls that look like method calls by a faster PyMethodCallNode
""" """
in_loop = False
def visit_SingleAssignmentNode(self, node): def visit_SingleAssignmentNode(self, node):
"""Avoid redundant initialisation of local variables before their """Avoid redundant initialisation of local variables before their
first assignment. first assignment.
...@@ -4623,7 +4625,9 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin): ...@@ -4623,7 +4625,9 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin):
PyTypeObjectPtr = PyrexTypes.CPtrType(cython_scope.lookup('PyTypeObject').type) PyTypeObjectPtr = PyrexTypes.CPtrType(cython_scope.lookup('PyTypeObject').type)
node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr) node.args[1] = ExprNodes.CastNode(node.args[1], PyTypeObjectPtr)
elif (node.is_temp and function.type.is_pyobject and self.current_directives.get( elif (node.is_temp and function.type.is_pyobject and self.current_directives.get(
"optimize.unpack_method_calls_in_pyinit" if self.current_env().is_module_scope else "optimize.unpack_method_calls")): "optimize.unpack_method_calls_in_pyinit"
if not self.in_loop and self.current_env().is_module_scope
else "optimize.unpack_method_calls")):
# optimise simple Python methods calls # optimise simple Python methods calls
if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not ( if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not (
node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)): node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)):
...@@ -4679,6 +4683,15 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin): ...@@ -4679,6 +4683,15 @@ class FinalOptimizePhase(Visitor.EnvTransform, Visitor.NodeRefCleanupMixin):
return node.arg return node.arg
return node return node
def visit_LoopNode(self, node):
"""Remember when we enter a loop as some expensive optimisations might still be worth it there.
"""
old_val = self.in_loop
self.in_loop = True
self.visitchildren(node)
self.in_loop = old_val
return node
class ConsolidateOverflowCheck(Visitor.CythonTransform): class ConsolidateOverflowCheck(Visitor.CythonTransform):
""" """
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment