Kaydet (Commit) 99ee9c70 authored tarafından Victor Stinner's avatar Victor Stinner

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.
üst 69112676
...@@ -208,30 +208,32 @@ calliter_traverse(calliterobject *it, visitproc visit, void *arg) ...@@ -208,30 +208,32 @@ 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 *result;
PyObject *args = PyTuple_New(0);
PyObject *result; if (it->it_callable == NULL) {
if (args == 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);
if (ok == 0) ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
return result; /* Common case, fast path */ if (ok == 0) {
Py_DECREF(result); return result; /* Common case, fast path */
if (ok > 0) {
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
}
} }
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
PyErr_Clear(); Py_DECREF(result);
if (ok > 0) {
Py_CLEAR(it->it_callable); Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel); Py_CLEAR(it->it_sentinel);
} }
} }
else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
PyErr_Clear();
Py_CLEAR(it->it_callable);
Py_CLEAR(it->it_sentinel);
}
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment