Commit 282c5084 authored by Stefan Behnel's avatar Stefan Behnel

unbound methods/classmethods use PyMethodObject in Py3 as well, so include...

unbound methods/classmethods use PyMethodObject in Py3 as well, so include them in method call optimisation
parent 7a7821a9
......@@ -4837,22 +4837,20 @@ class PyMethodCallNode(SimpleCallNode):
arg_offset_cname = code.funcstate.allocate_temp(PyrexTypes.c_py_ssize_t_type, manage_ref=False)
code.putln("%s = 0;" % arg_offset_cname)
def attribute_is_likely_bound_method(attr):
def attribute_is_likely_method(attr):
obj = attr.obj
if obj.type is Builtin.type_type:
return False # more likely to be an unbound method
if obj.is_name and obj.entry.is_pyglobal:
return False # more likely to be a function
return True
if self.function.is_attribute:
likely_method = 'likely' if attribute_is_likely_bound_method(self.function) else 'unlikely'
likely_method = 'likely' if attribute_is_likely_method(self.function) else 'unlikely'
elif self.function.is_name and self.function.cf_state:
# not an attribute itself, but might have been assigned from one (e.g. bound method)
for assignment in self.function.cf_state:
value = assignment.rhs
if value and value.is_attribute and value.obj.type.is_pyobject:
if attribute_is_likely_bound_method(value):
if attribute_is_likely_method(value):
likely_method = 'likely'
break
else:
......
......@@ -3770,9 +3770,7 @@ class FinalOptimizePhase(Visitor.CythonTransform, Visitor.NodeRefCleanupMixin):
node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)):
# simple call, now exclude calls to objects that are definitely not methods
may_be_a_method = True
if function.type is Builtin.type_type:
may_be_a_method = False
elif function.is_name:
if function.is_name:
if function.entry.is_builtin:
may_be_a_method = False
elif function.cf_state:
......
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