diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-01-03 00:58:17 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-01-03 00:58:17 (GMT) |
commit | 6f7c0ae46d66593b4ca0f248b94b9e1d567114bb (patch) | |
tree | ef4dff87f24514fe917ba615dff933ca248e33aa /Objects/funcobject.c | |
parent | b03beefb24322ba5bf75e50af00350afb6512731 (diff) | |
download | cpython-6f7c0ae46d66593b4ca0f248b94b9e1d567114bb.zip cpython-6f7c0ae46d66593b4ca0f248b94b9e1d567114bb.tar.gz cpython-6f7c0ae46d66593b4ca0f248b94b9e1d567114bb.tar.bz2 |
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).
Diffstat (limited to 'Objects/funcobject.c')
-rw-r--r-- | Objects/funcobject.c | 53 |
1 files changed, 6 insertions, 47 deletions
diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 63aa9de..a3af4b3 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -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; - - 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); + PyObject **stack; + Py_ssize_t nargs; - 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 */ |