Commit a51df339 authored by Stefan Behnel's avatar Stefan Behnel

speed up non-kwargs Python function/method calls by up to 20% by avoiding tuple creation

parent f4d72389
......@@ -5574,6 +5574,29 @@ class PyMethodCallNode(SimpleCallNode):
else:
arg_offset = arg_offset_cname
code.putln("#if CYTHON_FAST_PYCALL")
code.putln("if (PyFunction_Check(%s)) {" % function)
code.putln("PyObject *%s[%d] = {%s, %s};" % (
Naming.quick_temp_cname,
len(args)+1,
self_arg,
', '.join(arg.py_result() for arg in args)))
code.putln("%s = __Pyx_PyFunction_FastCall(%s, %s+1-%s, %d+%s, NULL); %s" % (
self.result(),
function,
Naming.quick_temp_cname,
arg_offset,
len(args),
arg_offset,
code.error_goto_if_null(self.result(), self.pos)))
code.put_xdecref_clear(self_arg, py_object_type)
code.put_gotref(self.py_result())
for arg in args:
arg.generate_disposal_code(code)
code.putln("} else")
code.putln("#endif")
code.putln("{")
args_tuple = code.funcstate.allocate_temp(py_object_type, manage_ref=True)
code.putln("%s = PyTuple_New(%d+%s); %s" % (
args_tuple, len(args), arg_offset,
......@@ -5614,6 +5637,7 @@ class PyMethodCallNode(SimpleCallNode):
if len(args) == 1:
code.putln("}")
code.putln("}") # !CYTHON_FAST_PYCALL
if reuse_function_temp:
self.function.generate_disposal_code(code)
......
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