Minor performance tweak for deque.index() with a start argument (GH-9440)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 935b434..267cf07 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1050,8 +1050,10 @@
start = stop;
assert(0 <= start && start <= stop && stop <= Py_SIZE(deque));
- /* XXX Replace this loop with faster code from deque_item() */
- for (i=0 ; i<start ; i++) {
+ for (i=0 ; i < start - BLOCKLEN ; i += BLOCKLEN) {
+ b = b->rightlink;
+ }
+ for ( ; i < start ; i++) {
index++;
if (index == BLOCKLEN) {
b = b->rightlink;