Skip to content

Commit 88fc1b1

Browse files
committed
Fast path for the common case (zero new items).
1 parent ea9511e commit 88fc1b1

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Modules/itertoolsmodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,14 @@ batched_next(batchedobject *bo)
160160
}
161161
PyList_SET_ITEM(result, i, item);
162162
}
163-
if (i < bo->batch_size) {
163+
if (i > 0 && i < bo->batch_size) {
164164
PyObject *short_list = PyList_GetSlice(result, 0, i);
165165
Py_SETREF(result, short_list);
166166
if (result == NULL) {
167167
return NULL;
168168
}
169169
}
170-
if (PyList_GET_SIZE(result) > 0) {
170+
if (i > 0) {
171171
return result;
172172
}
173173
Py_CLEAR(bo->it);

Objects/listobject.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "pycore_object.h" // _PyObject_GC_TRACK()
88
#include "pycore_tuple.h" // _PyTuple_FromArray()
99
#include <stddef.h>
10+
#include <stdio.h>
1011

1112
/*[clinic input]
1213
class list "PyListObject *" "&PyList_Type"

0 commit comments

Comments
 (0)