mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Squash a few calls to the hideously expensive PyObject_CallObject(o,a)
-- replace then with slightly faster PyObject_Call(o,a,NULL). (The difference is that the latter requires a to be a tuple; the former allows other values and wraps them in a tuple if necessary; it involves two more levels of C function calls to accomplish all that.)
This commit is contained in:
parent
c13f724af0
commit
84b2bed435
5 changed files with 37 additions and 12 deletions
|
@ -3257,7 +3257,7 @@ SLOT0(slot_nb_absolute, "__abs__")
|
|||
static int
|
||||
slot_nb_nonzero(PyObject *self)
|
||||
{
|
||||
PyObject *func, *res;
|
||||
PyObject *func, *res, *args;
|
||||
static PyObject *nonzero_str, *len_str;
|
||||
|
||||
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
|
||||
|
@ -3272,7 +3272,11 @@ slot_nb_nonzero(PyObject *self)
|
|||
return 1;
|
||||
}
|
||||
}
|
||||
res = PyObject_CallObject(func, NULL);
|
||||
args = res = PyTuple_New(0);
|
||||
if (args != NULL) {
|
||||
res = PyObject_Call(func, args, NULL);
|
||||
Py_DECREF(args);
|
||||
}
|
||||
Py_DECREF(func);
|
||||
if (res == NULL)
|
||||
return -1;
|
||||
|
@ -3651,9 +3655,14 @@ slot_tp_iter(PyObject *self)
|
|||
|
||||
func = lookup_method(self, "__iter__", &iter_str);
|
||||
if (func != NULL) {
|
||||
res = PyObject_CallObject(func, NULL);
|
||||
Py_DECREF(func);
|
||||
return res;
|
||||
PyObject *args;
|
||||
args = res = PyTuple_New(0);
|
||||
if (args != NULL) {
|
||||
res = PyObject_Call(func, args, NULL);
|
||||
Py_DECREF(args);
|
||||
}
|
||||
Py_DECREF(func);
|
||||
return res;
|
||||
}
|
||||
PyErr_Clear();
|
||||
func = lookup_method(self, "__getitem__", &getitem_str);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue