Skip to content

Commit

Permalink
GH-98363: Slicing isn't necessary. A size reduction will suffice. (GH…
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettinger committed Oct 22, 2022
1 parent f7f55a5 commit 5871e19
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Modules/itertoolsmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit 5871e19

Please sign in to comment.