[Python-checkins] cpython: calliter_iternext() now uses fast call

victor.stinner python-checkins at python.org
Fri Aug 19 12:53:54 EDT 2016


https://hg.python.org/cpython/rev/124d5d0ef81f
changeset:   102779:124d5d0ef81f
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Fri Aug 19 18:47:10 2016 +0200
summary:
  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.

files:
  Objects/iterobject.c |  40 ++++++++++++++++---------------
  1 files changed, 21 insertions(+), 19 deletions(-)


diff --git a/Objects/iterobject.c b/Objects/iterobject.c
--- a/Objects/iterobject.c
+++ b/Objects/iterobject.c
@@ -208,30 +208,32 @@
 static PyObject *
 calliter_iternext(calliterobject *it)
 {
-    if (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(it->it_sentinel, result, Py_EQ);
-            if (ok == 0)
-                return result; /* Common case, fast path */
-            Py_DECREF(result);
-            if (ok > 0) {
-                Py_CLEAR(it->it_callable);
-                Py_CLEAR(it->it_sentinel);
-            }
+    PyObject *result;
+
+    if (it->it_callable == NULL) {
+        return NULL;
+    }
+
+    result = _PyObject_FastCall(it->it_callable, NULL, 0, NULL);
+    if (result != NULL) {
+        int ok;
+
+        ok = PyObject_RichCompareBool(it->it_sentinel, result, Py_EQ);
+        if (ok == 0) {
+            return result; /* Common case, fast path */
         }
-        else if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
-            PyErr_Clear();
+
+        Py_DECREF(result);
+        if (ok > 0) {
             Py_CLEAR(it->it_callable);
             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;
 }
 

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list