Replace PyObject_CallFunctionObjArgs() with fastcall

* PyObject_CallFunctionObjArgs(func, NULL) => _PyObject_CallNoArg(func)
* PyObject_CallFunctionObjArgs(func, arg, NULL) => _PyObject_CallArg1(func, arg)

PyObject_CallFunctionObjArgs() allocates 40 bytes on the C stack and requires
extra work to "parse" C arguments to build a C array of PyObject*.

_PyObject_CallNoArg() and _PyObject_CallArg1() are simpler and don't allocate
memory on the C stack.

This change is part of the fastcall project. The change on listsort() is
related to the issue #23507.
This commit is contained in:
Victor Stinner 2016-12-01 14:43:22 +01:00
parent 8be1c39eb3
commit 27580c1fb5
33 changed files with 71 additions and 83 deletions

View file

@ -415,7 +415,7 @@ call_show_warning(PyObject *category, PyObject *text, PyObject *message,
if (msg == NULL)
goto error;
res = PyObject_CallFunctionObjArgs(show_fn, msg, NULL);
res = _PyObject_CallArg1(show_fn, msg);
Py_DECREF(show_fn);
Py_DECREF(msg);

View file

@ -469,7 +469,7 @@ filter_next(filterobject *lz)
ok = PyObject_IsTrue(item);
} else {
PyObject *good;
good = PyObject_CallFunctionObjArgs(lz->func, item, NULL);
good = _PyObject_CallArg1(lz->func, item);
if (good == NULL) {
Py_DECREF(item);
return NULL;
@ -1519,7 +1519,7 @@ min_max(PyObject *args, PyObject *kwds, int op)
while (( item = PyIter_Next(it) )) {
/* get the value from the key function */
if (keyfunc != NULL) {
val = PyObject_CallFunctionObjArgs(keyfunc, item, NULL);
val = _PyObject_CallArg1(keyfunc, item);
if (val == NULL)
goto Fail_it_item;
}
@ -2044,9 +2044,9 @@ builtin_round(PyObject *self, PyObject *args, PyObject *kwds)
}
if (ndigits == NULL || ndigits == Py_None)
result = PyObject_CallFunctionObjArgs(round, NULL);
result = _PyObject_CallNoArg(round);
else
result = PyObject_CallFunctionObjArgs(round, ndigits, NULL);
result = _PyObject_CallArg1(round, ndigits);
Py_DECREF(round);
return result;
}

View file

@ -1756,7 +1756,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
Py_DECREF(value);
goto error;
}
res = PyObject_CallFunctionObjArgs(hook, value, NULL);
res = _PyObject_CallArg1(hook, value);
Py_DECREF(value);
if (res == NULL)
goto error;
@ -3062,7 +3062,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
Py_DECREF(mgr);
if (enter == NULL)
goto error;
res = PyObject_CallFunctionObjArgs(enter, NULL);
res = _PyObject_CallNoArg(enter);
Py_DECREF(enter);
if (res == NULL)
goto error;
@ -3096,7 +3096,7 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
}
SET_TOP(exit);
Py_DECREF(mgr);
res = PyObject_CallFunctionObjArgs(enter, NULL);
res = _PyObject_CallNoArg(enter);
Py_DECREF(enter);
if (res == NULL)
goto error;

View file

@ -985,7 +985,7 @@ get_path_importer(PyObject *path_importer_cache, PyObject *path_hooks,
PyObject *hook = PyList_GetItem(path_hooks, j);
if (hook == NULL)
return NULL;
importer = PyObject_CallFunctionObjArgs(hook, p, NULL);
importer = _PyObject_CallArg1(hook, p);
if (importer != NULL)
break;

View file

@ -1098,7 +1098,7 @@ _PySys_GetSizeOf(PyObject *o)
Py_TYPE(o)->tp_name);
}
else {
res = PyObject_CallFunctionObjArgs(method, NULL);
res = _PyObject_CallNoArg(method);
Py_DECREF(method);
}