mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +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
|
@ -829,7 +829,7 @@ readinst(char *buf, int buf_size, PyObject *meth)
|
||||||
|
|
||||||
PyTuple_SET_ITEM(arg, 0, bytes);
|
PyTuple_SET_ITEM(arg, 0, bytes);
|
||||||
|
|
||||||
if ((str = PyObject_CallObject(meth, arg)) == NULL)
|
if ((str = PyObject_Call(meth, arg, NULL)) == NULL)
|
||||||
goto finally;
|
goto finally;
|
||||||
|
|
||||||
/* XXX what to do if it returns a Unicode string? */
|
/* XXX what to do if it returns a Unicode string? */
|
||||||
|
|
|
@ -1727,7 +1727,7 @@ PyObject_CallFunction(PyObject *callable, char *format, ...)
|
||||||
return NULL;
|
return NULL;
|
||||||
args = a;
|
args = a;
|
||||||
}
|
}
|
||||||
retval = PyObject_CallObject(callable, args);
|
retval = PyObject_Call(callable, args, NULL);
|
||||||
|
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
|
|
||||||
|
@ -1774,7 +1774,7 @@ PyObject_CallMethod(PyObject *o, char *name, char *format, ...)
|
||||||
args = a;
|
args = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = PyObject_CallObject(func, args);
|
retval = PyObject_Call(func, args, NULL);
|
||||||
|
|
||||||
Py_DECREF(args);
|
Py_DECREF(args);
|
||||||
Py_DECREF(func);
|
Py_DECREF(func);
|
||||||
|
|
|
@ -163,7 +163,12 @@ static PyObject *
|
||||||
calliter_iternext(calliterobject *it)
|
calliter_iternext(calliterobject *it)
|
||||||
{
|
{
|
||||||
if (it->it_callable != NULL) {
|
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) {
|
if (result != NULL) {
|
||||||
int ok;
|
int ok;
|
||||||
ok = PyObject_RichCompareBool(result,
|
ok = PyObject_RichCompareBool(result,
|
||||||
|
|
|
@ -3257,7 +3257,7 @@ SLOT0(slot_nb_absolute, "__abs__")
|
||||||
static int
|
static int
|
||||||
slot_nb_nonzero(PyObject *self)
|
slot_nb_nonzero(PyObject *self)
|
||||||
{
|
{
|
||||||
PyObject *func, *res;
|
PyObject *func, *res, *args;
|
||||||
static PyObject *nonzero_str, *len_str;
|
static PyObject *nonzero_str, *len_str;
|
||||||
|
|
||||||
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
|
func = lookup_maybe(self, "__nonzero__", &nonzero_str);
|
||||||
|
@ -3272,7 +3272,11 @@ slot_nb_nonzero(PyObject *self)
|
||||||
return 1;
|
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);
|
Py_DECREF(func);
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3651,9 +3655,14 @@ slot_tp_iter(PyObject *self)
|
||||||
|
|
||||||
func = lookup_method(self, "__iter__", &iter_str);
|
func = lookup_method(self, "__iter__", &iter_str);
|
||||||
if (func != NULL) {
|
if (func != NULL) {
|
||||||
res = PyObject_CallObject(func, NULL);
|
PyObject *args;
|
||||||
Py_DECREF(func);
|
args = res = PyTuple_New(0);
|
||||||
return res;
|
if (args != NULL) {
|
||||||
|
res = PyObject_Call(func, args, NULL);
|
||||||
|
Py_DECREF(args);
|
||||||
|
}
|
||||||
|
Py_DECREF(func);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
func = lookup_method(self, "__getitem__", &getitem_str);
|
func = lookup_method(self, "__getitem__", &getitem_str);
|
||||||
|
|
|
@ -327,12 +327,16 @@ fp_readl(char *s, int size, struct tok_state *tok)
|
||||||
#ifndef Py_USING_UNICODE
|
#ifndef Py_USING_UNICODE
|
||||||
/* In a non-Unicode built, this should never be called. */
|
/* In a non-Unicode built, this should never be called. */
|
||||||
Py_FatalError("fp_readl should not be called in this build.");
|
Py_FatalError("fp_readl should not be called in this build.");
|
||||||
return NULL;
|
return NULL; /* Keep compiler happy (not reachable) */
|
||||||
#else
|
#else
|
||||||
PyObject* utf8;
|
PyObject* utf8;
|
||||||
PyObject* buf = tok->decoding_buffer;
|
PyObject* buf = tok->decoding_buffer;
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
buf = PyObject_CallObject(tok->decoding_readline, NULL);
|
PyObject *args = PyTuple_New(0);
|
||||||
|
if (args == NULL)
|
||||||
|
return error_ret(tok);
|
||||||
|
buf = PyObject_Call(tok->decoding_readline, args, NULL);
|
||||||
|
Py_DECREF(args);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return error_ret(tok);
|
return error_ret(tok);
|
||||||
} else {
|
} else {
|
||||||
|
@ -464,7 +468,14 @@ decoding_feof(struct tok_state *tok)
|
||||||
} else {
|
} else {
|
||||||
PyObject* buf = tok->decoding_buffer;
|
PyObject* buf = tok->decoding_buffer;
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
buf = PyObject_CallObject(tok->decoding_readline, NULL);
|
PyObject *args = PyTuple_New(0);
|
||||||
|
if (args == NULL) {
|
||||||
|
error_ret(tok);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
buf = PyObject_Call(tok->decoding_readline,
|
||||||
|
args, NULL);
|
||||||
|
Py_DECREF(args);
|
||||||
if (buf == NULL) {
|
if (buf == NULL) {
|
||||||
error_ret(tok);
|
error_ret(tok);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue