Commit a6a2d569 authored by Stefan Behnel's avatar Stefan Behnel

faster call to builtin type()

parent 44b50ac1
...@@ -690,7 +690,6 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform): ...@@ -690,7 +690,6 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
]) ])
def _handle_simple_function_getattr(self, node, pos_args): def _handle_simple_function_getattr(self, node, pos_args):
# not really a builtin *type*, but worth optimising anyway
args = pos_args.args args = pos_args.args
if len(args) == 2: if len(args) == 2:
node = ExprNodes.PythonCapiCallNode( node = ExprNodes.PythonCapiCallNode(
...@@ -710,6 +709,23 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform): ...@@ -710,6 +709,23 @@ class OptimizeBuiltinCalls(Visitor.VisitorTransform):
"expected 2 or 3, found %d" % len(args)) "expected 2 or 3, found %d" % len(args))
return node return node
Pyx_Type_func_type = PyrexTypes.CFuncType(
Builtin.type_type, [
PyrexTypes.CFuncTypeArg("object", PyrexTypes.py_object_type, None)
])
def _handle_simple_function_type(self, node, pos_args):
args = pos_args.args
if len(args) != 1:
return node
node = ExprNodes.PythonCapiCallNode(
node.pos, "__Pyx_Type", self.Pyx_Type_func_type,
args = args,
is_temp = node.is_temp,
utility_code = pytype_utility_code,
)
return node
### methods of builtin types ### methods of builtin types
PyObject_Append_func_type = PyrexTypes.CFuncType( PyObject_Append_func_type = PyrexTypes.CFuncType(
...@@ -813,6 +829,17 @@ impl = "" ...@@ -813,6 +829,17 @@ impl = ""
) )
pytype_utility_code = UtilityCode(
proto = """
static INLINE PyObject* __Pyx_Type(PyObject* o) {
PyObject* type = (PyObject*) Py_TYPE(o);
Py_INCREF(type);
return type;
}
"""
)
class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
"""Calculate the result of constant expressions to store it in """Calculate the result of constant expressions to store it in
``expr_node.constant_result``, and replace trivial cases by their ``expr_node.constant_result``, and replace trivial cases by their
......
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