[Python-checkins] cpython: Refactor deque_traverse().

raymond.hettinger python-checkins at python.org
Sun Jul 7 00:02:47 CEST 2013


http://hg.python.org/cpython/rev/3555cc0ca35b
changeset:   84466:3555cc0ca35b
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jul 06 11:58:09 2013 -1000
summary:
  Refactor deque_traverse().

Hoist conditional expression out of the loop.
Use rightblock as the guard instead of checking for NULL.

files:
  Modules/_collectionsmodule.c |  12 ++++++------
  1 files changed, 6 insertions(+), 6 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -805,17 +805,17 @@
     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;
 }
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list