]> granicus.if.org Git - python/commitdiff
Precomputing the number iterations allows the inner-loop to be vectorizable.
authorRaymond Hettinger <python@rcn.com>
Sat, 26 Sep 2015 09:14:50 +0000 (02:14 -0700)
committerRaymond Hettinger <python@rcn.com>
Sat, 26 Sep 2015 09:14:50 +0000 (02:14 -0700)
Modules/_collectionsmodule.c

index 2dcdf8b5f4bdbfaaea6d313c6d20fbfed65f8c48..487c7657b095baf6c0fe402b3d1afc65cd400d5e 100644 (file)
@@ -557,7 +557,7 @@ static void deque_clear(dequeobject *deque);
 static PyObject *
 deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
 {
-    Py_ssize_t i, size;
+    Py_ssize_t i, m, size;
     PyObject *seq;
     PyObject *rv;
 
@@ -598,7 +598,11 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
                 MARK_END(b->rightlink);
                 deque->rightindex = -1;
             }
-            for ( ; i < n-1 && deque->rightindex != BLOCKLEN - 1 ; i++) {
+            m = n - 1 - i;
+            if (m > BLOCKLEN - 1 - deque->rightindex)
+                m = BLOCKLEN - 1 - deque->rightindex;
+            i += m;
+            while (m--) {
                 deque->rightindex++;
                 Py_INCREF(item);
                 deque->rightblock->data[deque->rightindex] = item;