[Python-checkins] cpython: Minor tweak. Make the maxlen comparisons a little more clear and consistent.

raymond.hettinger python-checkins at python.org
Sat Oct 10 23:56:06 EDT 2015


https://hg.python.org/cpython/rev/9165e297d65b
changeset:   98666:9165e297d65b
user:        Raymond Hettinger <python at rcn.com>
date:        Sat Oct 10 23:56:02 2015 -0400
summary:
  Minor tweak.  Make the maxlen comparisons a little more clear and consistent.

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
@@ -281,7 +281,7 @@
 static void
 deque_trim_right(dequeobject *deque)
 {
-    if (deque->maxlen != -1 && Py_SIZE(deque) > deque->maxlen) {
+    if (deque->maxlen >= 0 && Py_SIZE(deque) > deque->maxlen) {
         PyObject *rv = deque_pop(deque, NULL);
         assert(rv != NULL);
         assert(Py_SIZE(deque) <= deque->maxlen);
@@ -292,7 +292,7 @@
 static void
 deque_trim_left(dequeobject *deque)
 {
-    if (deque->maxlen != -1 && Py_SIZE(deque) > deque->maxlen) {
+    if (deque->maxlen >= 0 && Py_SIZE(deque) > deque->maxlen) {
         PyObject *rv = deque_popleft(deque, NULL);
         assert(rv != NULL);
         assert(Py_SIZE(deque) <= deque->maxlen);
@@ -385,7 +385,7 @@
 {
     PyObject *it, *item;
     PyObject *(*iternext)(PyObject *);
-    int trim = (deque->maxlen != -1);
+    int trim = (deque->maxlen >= 0);
 
     /* Handle case where id(deque) == id(iterable) */
     if ((PyObject *)deque == iterable) {
@@ -447,7 +447,7 @@
 {
     PyObject *it, *item;
     PyObject *(*iternext)(PyObject *);
-    int trim = (deque->maxlen != -1);
+    int trim = (deque->maxlen >= 0);
 
     /* Handle case where id(deque) == id(iterable) */
     if ((PyObject *)deque == iterable) {
@@ -686,7 +686,7 @@
         /* common case, repeating a single element */
         PyObject *item = deque->leftblock->data[deque->leftindex];
 
-        if (deque->maxlen != -1 && n > deque->maxlen)
+        if (deque->maxlen >= 0 && n > deque->maxlen)
             n = deque->maxlen;
 
         if (n > MAX_DEQUE_LEN)
@@ -1355,7 +1355,7 @@
         Py_ReprLeave(deque);
         return NULL;
     }
-    if (((dequeobject *)deque)->maxlen != -1)
+    if (((dequeobject *)deque)->maxlen >= 0)
         result = PyUnicode_FromFormat("deque(%R, maxlen=%zd)",
                                       aslist, ((dequeobject *)deque)->maxlen);
     else

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


More information about the Python-checkins mailing list