mirror of https://github.com/python/cpython
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:
parent
b03beefb24
commit
6f7c0ae46d
|
@ -563,55 +563,14 @@ func_traverse(PyFunctionObject *f, visitproc visit, void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
function_call(PyObject *func, PyObject *arg, PyObject *kw)
|
function_call(PyObject *func, PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
PyObject *result;
|
PyObject **stack;
|
||||||
PyObject *argdefs;
|
Py_ssize_t nargs;
|
||||||
PyObject *kwtuple = NULL;
|
|
||||||
PyObject **d, **k;
|
|
||||||
Py_ssize_t nk, nd;
|
|
||||||
|
|
||||||
argdefs = PyFunction_GET_DEFAULTS(func);
|
stack = &PyTuple_GET_ITEM(args, 0);
|
||||||
if (argdefs != NULL && PyTuple_Check(argdefs)) {
|
nargs = PyTuple_GET_SIZE(args);
|
||||||
d = &PyTuple_GET_ITEM((PyTupleObject *)argdefs, 0);
|
return _PyFunction_FastCallDict(func, stack, nargs, kwargs);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bind a function to an object */
|
/* Bind a function to an object */
|
||||||
|
|
Loading…
Reference in New Issue