diff options
author | Raymond Hettinger <python@rcn.com> | 2015-10-11 03:56:02 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-10-11 03:56:02 (GMT) |
commit | a7f63009d6df9c6ae57e6835857d6c5fda024930 (patch) | |
tree | 765b9c6d1db330b23f0d2957f13f4c81b42e8c12 | |
parent | 10dcff7a0415b302d5eb8de8e7763c7eab85e3dc (diff) | |
download | cpython-a7f63009d6df9c6ae57e6835857d6c5fda024930.zip cpython-a7f63009d6df9c6ae57e6835857d6c5fda024930.tar.gz cpython-a7f63009d6df9c6ae57e6835857d6c5fda024930.tar.bz2 |
Minor tweak. Make the maxlen comparisons a little more clear and consistent.
-rw-r--r-- | Modules/_collectionsmodule.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 4ea9140..52f40b2 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -281,7 +281,7 @@ PyDoc_STRVAR(popleft_doc, "Remove and return the leftmost element."); 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 @@ deque_trim_right(dequeobject *deque) 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 @@ deque_extend(dequeobject *deque, PyObject *iterable) { 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 @@ deque_extendleft(dequeobject *deque, PyObject *iterable) { 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 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n) /* 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 @@ deque_repr(PyObject *deque) 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 |