diff options
author | Guido van Rossum <guido@python.org> | 2002-08-16 17:01:09 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2002-08-16 17:01:09 (GMT) |
commit | 84b2bed4359e27070fe2eac4b464d4a1bc6e150d (patch) | |
tree | 0d1e50962419f5bf7e69bbc899b29a8d762e5d08 /Objects | |
parent | c13f724af0a09d515efae57b902a1270b6aba4ac (diff) | |
download | cpython-84b2bed4359e27070fe2eac4b464d4a1bc6e150d.zip cpython-84b2bed4359e27070fe2eac4b464d4a1bc6e150d.tar.gz cpython-84b2bed4359e27070fe2eac4b464d4a1bc6e150d.tar.bz2 |
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.)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/abstract.c | 4 | ||||
-rw-r--r-- | Objects/iterobject.c | 7 | ||||
-rw-r--r-- | Objects/typeobject.c | 19 |
3 files changed, 22 insertions, 8 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c index fc73a9f..9940fd3 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -1727,7 +1727,7 @@ PyObject_CallFunction(PyObject *callable, char *format, ...) return NULL; args = a; } - retval = PyObject_CallObject(callable, args); + retval = PyObject_Call(callable, args, NULL); Py_DECREF(args); @@ -1774,7 +1774,7 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...) args = a; } - retval = PyObject_CallObject(func, args); + retval = PyObject_Call(func, args, NULL); Py_DECREF(args); Py_DECREF(func); diff --git a/Objects/iterobject.c b/Objects/iterobject.c index 4dc225a..2e1caae 100644 --- a/Objects/iterobject.c +++ b/Objects/iterobject.c @@ -163,7 +163,12 @@ static PyObject * calliter_iternext(calliterobject *it) { if (it->it_callable != NULL) { - PyObject *result = PyObject_CallObject(it->it_callable, NULL); + PyObject *args = PyTuple_New(0); + PyObject *result; + if (args == NULL) + return NULL; + result = PyObject_Call(it->it_callable, args, NULL); + Py_DECREF(args); if (result != NULL) { int ok; ok = PyObject_RichCompareBool(result, diff --git a/Objects/typeobject.c b/Objects/typeobject.c index c3c5893..a12e7df 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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); |