Skip to content

Commit 99ee9c7

Browse files
committed
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.
1 parent 6911267 commit 99ee9c7

1 file changed

Lines changed: 21 additions & 19 deletions

File tree

Objects/iterobject.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -208,30 +208,32 @@ calliter_traverse(calliterobject *it, visitproc visit, void *arg)
208208
static PyObject *
209209
calliter_iternext(calliterobject *it)
210210
{
211-
if (it->it_callable != NULL) {
212-
PyObject *args = PyTuple_New(0);
213-
PyObject *result;
214-
if (args == NULL)
215-
return NULL;
216-
result = PyObject_Call(it->it_callable, args, NULL);
217-
Py_DECREF(args);
218-
if (result != NULL) {
219-
int ok;
220-
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
221-
if (ok == 0)
222-
return result; /* Common case, fast path */
223-
Py_DECREF(result);
224-
if (ok > 0) {
225-
Py_CLEAR(it->it_callable);
226-
Py_CLEAR(it->it_sentinel);
227-
}
211+
PyObject *result;
212+
213+
if (it->it_callable == NULL) {
214+
return NULL;
215+
}
216+
217+
result = _PyObject_FastCall(it->it_callable, NULL, 0, NULL);
218+
if (result != NULL) {
219+
int ok;
220+
221+
ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
222+
if (ok == 0) {
223+
return result; /* Common case, fast path */
228224
}
229-
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
230-
PyErr_Clear();
225+
226+
Py_DECREF(result);
227+
if (ok > 0) {
231228
Py_CLEAR(it->it_callable);
232229
Py_CLEAR(it->it_sentinel);
233230
}
234231
}
232+
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
233+
PyErr_Clear();
234+
Py_CLEAR(it->it_callable);
235+
Py_CLEAR(it->it_sentinel);
236+
}
235237
return NULL;
236238
}
237239

0 commit comments

Comments
 (0)