]> granicus.if.org Git - python/commitdiff
calliter_iternext() now uses fast call
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:47:10 +0000 (18:47 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 19 Aug 2016 16:47:10 +0000 (18:47 +0200)
Issue #27128: calliter_iternext() now calls _PyObject_FastCall() to avoid a
temporary empty tuple.

Cleanup also the code to reduce the indentation level.

Objects/iterobject.c

index ab29ff81a9595b26c446d5d75bb72314f5d33bb2..a8e6e1c0c75e1b7b11b49d7a696c35df9d39dc97 100644 (file)
@@ -208,30 +208,32 @@ calliter_traverse(calliterobject *it, visitproc visit, void *arg)
 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;
 }