]> granicus.if.org Git - python/commitdiff
Use a do-while loop in the inner loop for rotate (m is always greater than zero).
authorRaymond Hettinger <python@rcn.com>
Sun, 14 Jul 2013 00:03:58 +0000 (17:03 -0700)
committerRaymond Hettinger <python@rcn.com>
Sun, 14 Jul 2013 00:03:58 +0000 (17:03 -0700)
Modules/_collectionsmodule.c

index 44ed0b2f6a6e6e6da3794b856a8bc783584b75e4..21cc21dac9fda5a4f24da5b52352b8efb4420b21 100644 (file)
@@ -506,13 +506,15 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
             rightindex -= m;
             leftindex -= m;
             n -= m;
-            while (m--)
+            do {
                 *(dest--) = *(src--);
+            } while (--m);
         }
 
         if (rightindex == -1) {
             block *prevblock = rightblock->leftlink;
             assert(leftblock != rightblock);
+            assert(b == NULL);
             b = rightblock;
             CHECK_NOT_END(prevblock);
             MARK_END(prevblock->rightlink);
@@ -551,13 +553,15 @@ _deque_rotate(dequeobject *deque, Py_ssize_t n)
             leftindex += m;
             rightindex += m;
             n += m;
-            while (m--)
+            do {
                 *(dest++) = *(src++);
+            } while (--m);
         }
 
         if (leftindex == BLOCKLEN) {
             block *nextblock = leftblock->rightlink;
             assert(leftblock != rightblock);
+            assert(b == NULL);
             b = leftblock;
             CHECK_NOT_END(nextblock);
             MARK_END(nextblock->leftlink);