[Python-checkins] cpython: Remove unnecessary branches from count() and reverse().

raymond.hettinger python-checkins at python.org
Sat Jul 6 21:07:28 CEST 2013


http://hg.python.org/cpython/rev/49a9c734304d
changeset:   84465:49a9c734304d
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Jul 06 09:07:06 2013 -1000
summary:
  Remove unnecessary branches from count() and reverse().

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


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -551,6 +551,8 @@
     for (i=0 ; i<n ; i++) {
         /* Validate that pointers haven't met in the middle */
         assert(leftblock != rightblock || leftindex < rightindex);
+        assert(leftblock != NULL);
+        assert(rightblock != NULL);
 
         /* Swap */
         tmp = leftblock->data[leftindex];
@@ -560,8 +562,6 @@
         /* Advance left block/index pair */
         leftindex++;
         if (leftindex == BLOCKLEN) {
-            if (leftblock->rightlink == NULL)
-                break;
             leftblock = leftblock->rightlink;
             leftindex = 0;
         }
@@ -569,8 +569,6 @@
         /* Step backwards with the right block/index pair */
         rightindex--;
         if (rightindex == -1) {
-            if (rightblock->leftlink == NULL)
-                break;
             rightblock = rightblock->leftlink;
             rightindex = BLOCKLEN - 1;
         }
@@ -594,6 +592,7 @@
     int cmp;
 
     for (i=0 ; i<n ; i++) {
+        assert(leftblock != NULL);
         item = leftblock->data[leftindex];
         cmp = PyObject_RichCompareBool(item, v, Py_EQ);
         if (cmp > 0)
@@ -610,8 +609,6 @@
         /* Advance left block/index pair */
         leftindex++;
         if (leftindex == BLOCKLEN) {
-            if (leftblock->rightlink == NULL)  /* can occur when i==n-1 */
-                break;
             leftblock = leftblock->rightlink;
             leftindex = 0;
         }

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


More information about the Python-checkins mailing list