mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
calliter_iternext() now uses fast call
Issue #27128: calliter_iternext() now calls _PyObject_FastCall() to avoid a temporary empty tuple. Cleanup also the code to reduce the indentation level.
This commit is contained in:
parent
6911267615
commit
99ee9c70a7
1 changed files with 21 additions and 19 deletions
|
@ -208,18 +208,21 @@ calliter_traverse(calliterobject *it, visitproc visit, void *arg)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
calliter_iternext(calliterobject *it)
|
calliter_iternext(calliterobject *it)
|
||||||
{
|
{
|
||||||
if (it->it_callable != NULL) {
|
|
||||||
PyObject *args = PyTuple_New(0);
|
|
||||||
PyObject *result;
|
PyObject *result;
|
||||||
if (args == NULL)
|
|
||||||
|
if (it->it_callable == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
result = PyObject_Call(it->it_callable, args, NULL);
|
}
|
||||||
Py_DECREF(args);
|
|
||||||
|
result = _PyObject_FastCall(it->it_callable, NULL, 0, NULL);
|
||||||
if (result != NULL) {
|
if (result != NULL) {
|
||||||
int ok;
|
int ok;
|
||||||
|
|
||||||
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
|
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
|
||||||
if (ok == 0)
|
if (ok == 0) {
|
||||||
return result; /* Common case, fast path */
|
return result; /* Common case, fast path */
|
||||||
|
}
|
||||||
|
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
if (ok > 0) {
|
if (ok > 0) {
|
||||||
Py_CLEAR(it->it_callable);
|
Py_CLEAR(it->it_callable);
|
||||||
|
@ -231,7 +234,6 @@ calliter_iternext(calliterobject *it)
|
||||||
Py_CLEAR(it->it_callable);
|
Py_CLEAR(it->it_callable);
|
||||||
Py_CLEAR(it->it_sentinel);
|
Py_CLEAR(it->it_sentinel);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue