[Python-checkins] cpython: Issue #28839: Optimize function_call()
victor.stinner
python-checkins at python.org
Mon Jan 2 20:05:46 EST 2017
https://hg.python.org/cpython/rev/5f7cd3b6c9b1
changeset: 105972:5f7cd3b6c9b1
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Jan 03 01:58:17 2017 +0100
summary:
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).
files:
Objects/funcobject.c | 53 +++----------------------------
1 files changed, 6 insertions(+), 47 deletions(-)
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -563,55 +563,14 @@
}
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 */
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list