Commit 7d386fe6 authored by Stefan Behnel's avatar Stefan Behnel

exclude calls to known but unoptimised builtins from method call optimisation

parent 6b84a0fb
...@@ -3754,20 +3754,22 @@ class FinalOptimizePhase(Visitor.CythonTransform, Visitor.NodeRefCleanupMixin): ...@@ -3754,20 +3754,22 @@ class FinalOptimizePhase(Visitor.CythonTransform, Visitor.NodeRefCleanupMixin):
Replace likely Python method calls by a specialised PyMethodCallNode. Replace likely Python method calls by a specialised PyMethodCallNode.
""" """
self.visitchildren(node) self.visitchildren(node)
if node.function.type.is_cfunction and node.function.is_name: function = node.function
if node.function.name == 'isinstance' and len(node.args) == 2: if function.type.is_cfunction and function.is_name:
if function.name == 'isinstance' and len(node.args) == 2:
type_arg = node.args[1] type_arg = node.args[1]
if type_arg.type.is_builtin_type and type_arg.type.name == 'type': if type_arg.type.is_builtin_type and type_arg.type.name == 'type':
cython_scope = self.context.cython_scope cython_scope = self.context.cython_scope
node.function.entry = cython_scope.lookup('PyObject_TypeCheck') function.entry = cython_scope.lookup('PyObject_TypeCheck')
node.function.type = node.function.entry.type function.type = function.entry.type
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 node.function.type.is_pyobject and node.function.type is not Builtin.type_type: elif node.is_temp and function.type.is_pyobject:
if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not ( if function.type is not Builtin.type_type and not (function.is_name and function.entry.is_builtin):
node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)): if isinstance(node.arg_tuple, ExprNodes.TupleNode) and not (
node = self.replace(node, ExprNodes.PyMethodCallNode.from_node( node.arg_tuple.mult_factor or (node.arg_tuple.is_literal and node.arg_tuple.args)):
node, function=node.function, arg_tuple=node.arg_tuple, type=node.type)) node = self.replace(node, ExprNodes.PyMethodCallNode.from_node(
node, function=function, arg_tuple=node.arg_tuple, type=node.type))
return node return node
def visit_PyTypeTestNode(self, node): def visit_PyTypeTestNode(self, node):
......
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