Issue #28839: Optimize function_call()

function_call() now simply calls _PyFunction_FastCallDict().

_PyFunction_FastCallDict() is more efficient: it contains fast paths for the
common case (optimized code object and no keyword argument).
This commit is contained in:
Victor Stinner 2017-01-03 01:58:17 +01:00
parent b03beefb24
commit 6f7c0ae46d
1 changed files with 6 additions and 47 deletions

View File

@ -563,55 +563,14 @@ func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
}
static PyObject *
function_call(PyObject *func, PyObject *arg, PyObject *kw)
function_call(PyObject *func, PyObject *args, PyObject *kwargs)
{
PyObject *result;
PyObject *argdefs;
PyObject *kwtuple = NULL;
PyObject **d, **k;
Py_ssize_t nk, nd;
PyObject **stack;
Py_ssize_t nargs;
argdefs = PyFunction_GET_DEFAULTS(func);
if (argdefs != NULL && PyTuple_Check(argdefs)) {
d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
nd = PyTuple_GET_SIZE(argdefs);
}
else {
d = NULL;
nd = 0;
}
if (kw != NULL && PyDict_Check(kw)) {
Py_ssize_t pos, i;
nk = PyDict_GET_SIZE(kw);
kwtuple = PyTuple_New(2*nk);
if (kwtuple == NULL)
return NULL;
k = &PyTuple_GET_ITEM(kwtuple, 0);
pos = i = 0;
while (PyDict_Next(kw, &pos, &k[i], &k[i+1])) {
Py_INCREF(k[i]);
Py_INCREF(k[i+1]);
i += 2;
}
nk = i/2;
}
else {
k = NULL;
nk = 0;
}
result = PyEval_EvalCodeEx(
PyFunction_GET_CODE(func),
PyFunction_GET_GLOBALS(func), (PyObject *)NULL,
&PyTuple_GET_ITEM(arg, 0), PyTuple_GET_SIZE(arg),
k, nk, d, nd,
PyFunction_GET_KW_DEFAULTS(func),
PyFunction_GET_CLOSURE(func));
Py_XDECREF(kwtuple);
return result;
stack = &PyTuple_GET_ITEM(args, 0);
nargs = PyTuple_GET_SIZE(args);
return _PyFunction_FastCallDict(func, stack, nargs, kwargs);
}
/* Bind a function to an object */