[Python-checkins] cpython: Minor consistency improvements to negative value comparisons.

raymond.hettinger python-checkins at python.org
Tue Sep 22 08:42:02 CEST 2015


https://hg.python.org/cpython/rev/0209061804da
changeset:   98168:0209061804da
user:        Raymond Hettinger <python at rcn.com>
date:        Mon Sep 21 23:41:56 2015 -0700
summary:
  Minor consistency improvements to negative value comparisons.

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


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -209,7 +209,7 @@
     Py_SIZE(deque)--;
     deque->state++;
 
-    if (deque->rightindex == -1) {
+    if (deque->rightindex < 0) {
         if (Py_SIZE(deque)) {
             prevblock = deque->rightblock->leftlink;
             assert(deque->leftblock != deque->rightblock);
@@ -715,7 +715,7 @@
                 *(dest++) = *(src++);
             } while (--m);
         }
-        if (rightindex == -1) {
+        if (rightindex < 0) {
             assert(leftblock != rightblock);
             assert(b == NULL);
             b = rightblock;
@@ -827,7 +827,7 @@
 
         /* Step backwards with the right block/index pair */
         rightindex--;
-        if (rightindex == -1) {
+        if (rightindex < 0) {
             rightblock = rightblock->leftlink;
             rightindex = BLOCKLEN - 1;
         }
@@ -1234,7 +1234,7 @@
         Py_DECREF(new_deque);
         return NULL;
     }
-    if (old_deque->maxlen == -1)
+    if (old_deque->maxlen < 0)
         return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "O", deque, NULL);
     else
         return PyObject_CallFunction((PyObject *)(Py_TYPE(deque)), "Oi",
@@ -1258,12 +1258,12 @@
         return NULL;
     }
     if (dict == NULL) {
-        if (deque->maxlen == -1)
+        if (deque->maxlen < 0)
             result = Py_BuildValue("O(O)", Py_TYPE(deque), aslist);
         else
             result = Py_BuildValue("O(On)", Py_TYPE(deque), aslist, deque->maxlen);
     } else {
-        if (deque->maxlen == -1)
+        if (deque->maxlen < 0)
             result = Py_BuildValue("O(OO)O", Py_TYPE(deque), aslist, Py_None, dict);
         else
             result = Py_BuildValue("O(On)O", Py_TYPE(deque), aslist, deque->maxlen, dict);
@@ -1354,7 +1354,7 @@
         }
         Py_DECREF(x);
         Py_DECREF(y);
-        if (b == -1)
+        if (b < 0)
             goto done;
     }
     /* We reached the end of one deque or both */
@@ -1437,7 +1437,7 @@
 static PyObject *
 deque_get_maxlen(dequeobject *deque)
 {
-    if (deque->maxlen == -1)
+    if (deque->maxlen < 0)
         Py_RETURN_NONE;
     return PyLong_FromSsize_t(deque->maxlen);
 }
@@ -1778,7 +1778,7 @@
     item = it->b->data[it->index];
     it->index--;
     it->counter--;
-    if (it->index == -1 && it->counter > 0) {
+    if (it->index < 0 && it->counter > 0) {
         CHECK_NOT_END(it->b->leftlink);
         it->b = it->b->leftlink;
         it->index = BLOCKLEN - 1;

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


More information about the Python-checkins mailing list