]> granicus.if.org Git - python/commitdiff
Refactor deque_traverse().
authorRaymond Hettinger <python@rcn.com>
Sat, 6 Jul 2013 21:58:09 +0000 (11:58 -1000)
committerRaymond Hettinger <python@rcn.com>
Sat, 6 Jul 2013 21:58:09 +0000 (11:58 -1000)
Hoist conditional expression out of the loop.
Use rightblock as the guard instead of checking for NULL.

Modules/_collectionsmodule.c

index 376a8e67706282e250e634e7bb58cce204d55c9c..0a98e01a3a72b2fcc89bd727027f57c7dadd3e95 100644 (file)
@@ -805,17 +805,17 @@ deque_traverse(dequeobject *deque, visitproc visit, void *arg)
     Py_ssize_t index;
     Py_ssize_t indexlo = deque->leftindex;
 
-    for (b = deque->leftblock; b != NULL; b = b->rightlink) {
-        const Py_ssize_t indexhi = b == deque->rightblock ?
-                                 deque->rightindex :
-                     BLOCKLEN - 1;
-
-        for (index = indexlo; index <= indexhi; ++index) {
+    for (b = deque->leftblock; b != deque->rightblock; b = b->rightlink) {
+        for (index = indexlo; index < BLOCKLEN ; index++) {
             item = b->data[index];
             Py_VISIT(item);
         }
         indexlo = 0;
     }
+    for (index = indexlo; index <= deque->rightindex; index++) {
+        item = b->data[index];
+        Py_VISIT(item);
+    }
     return 0;
 }