]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-98363: Slicing isn't necessary. A size reduction will suffice. (GH-98538)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Sat, 22 Oct 2022 12:21:06 +0000 (07:21 -0500)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 12:21:06 +0000 (07:21 -0500)
Modules/itertoolsmodule.c

index 578c2d942885486e721b270bbb82a6fb887d1001..381ec3b31d525eead762446af4f43fb5bf4030ab 100644 (file)
@@ -167,23 +167,22 @@ batched_next(batchedobject *bo)
 
  null_item:
     if (PyErr_Occurred()) {
-        if (PyErr_ExceptionMatches(PyExc_StopIteration)) {
-            PyErr_Clear();
-        } else {
-            /* input raised an exception other than StopIteration */
+        if (!PyErr_ExceptionMatches(PyExc_StopIteration)) {
+            /* Input raised an exception other than StopIteration */
             Py_CLEAR(bo->it);
             Py_DECREF(result);
             return NULL;
         }
+        PyErr_Clear();
     }
     if (i == 0) {
         Py_CLEAR(bo->it);
         Py_DECREF(result);
         return NULL;
     }
-    PyObject *short_list = PyList_GetSlice(result, 0, i);
-    Py_DECREF(result);
-    return short_list;
+    /* Elements in result[i:] are still NULL */
+    Py_SET_SIZE(result, i);
+    return result;
 }
 
 static PyTypeObject batched_type = {