summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2018-09-21 08:46:41 (GMT)
committerGitHub <noreply@github.com>2018-09-21 08:46:41 (GMT)
commitb46ad5431d2643f61e929c1ffec48766b2fafd75 (patch)
treed82d6b7498df61a8f86afdb38f5396c826b7c4a3 /Modules/_collectionsmodule.c
parentfb3e9c00ed79f4d880ab9a67aab861eb3660ec75 (diff)
downloadcpython-b46ad5431d2643f61e929c1ffec48766b2fafd75.zip
cpython-b46ad5431d2643f61e929c1ffec48766b2fafd75.tar.gz
cpython-b46ad5431d2643f61e929c1ffec48766b2fafd75.tar.bz2
Minor performance tweak for deque.index() with a start argument (GH-9440)
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c6
1 files changed, 4 insertions, 2 deletions
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 @@ deque_index(dequeobject *deque, PyObject *const *args, Py_ssize_t nargs)
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;