]> granicus.if.org Git - python/commitdiff
Optimization guides suggest copying memory in an ascending direction when possible.
authorRaymond Hettinger <python@rcn.com>
Mon, 2 Feb 2015 06:53:41 +0000 (22:53 -0800)
committerRaymond Hettinger <python@rcn.com>
Mon, 2 Feb 2015 06:53:41 +0000 (22:53 -0800)
Modules/_collectionsmodule.c

index b2783d2739580a288ee76eb9b5848b543a5cba1a..69d93ae6a69c140413fb81fad420c4af27803796 100644 (file)
@@ -534,13 +534,13 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
             if (m > leftindex)
                 m = leftindex;
             assert (m > 0 && m <= len);
-            src = &rightblock->data[rightindex];
-            dest = &leftblock->data[leftindex - 1];
             rightindex -= m;
             leftindex -= m;
+            src = &rightblock->data[rightindex + 1];
+            dest = &leftblock->data[leftindex];
             n -= m;
             do {
-                *(dest--) = *(src--);
+                *(dest++) = *(src++);
             } while (--m);
         }
         if (rightindex == -1) {