diff options
author | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2017-09-04 23:07:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-04 23:07:06 (GMT) |
commit | e1b0287c0440399e8cc855897113614fa5f6bc96 (patch) | |
tree | df41002e1cea4b28b27bc2f027ab28c71e144242 | |
parent | af64aff9f7de2ee60c20bfb331e8a00ea0521c1e (diff) | |
download | cpython-e1b0287c0440399e8cc855897113614fa5f6bc96.zip cpython-e1b0287c0440399e8cc855897113614fa5f6bc96.tar.gz cpython-e1b0287c0440399e8cc855897113614fa5f6bc96.tar.bz2 |
Code clean-up. Remove unnecessary pre-increment before the loop starts. (#3312)
-rw-r--r-- | Modules/_collectionsmodule.c | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index adbe789..8766d86 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -938,8 +938,7 @@ deque_reverse(dequeobject *deque, PyObject *unused) Py_ssize_t n = Py_SIZE(deque) >> 1; PyObject *tmp; - n++; - while (--n) { + while (--n >= 0) { /* Validate that pointers haven't met in the middle */ assert(leftblock != rightblock || leftindex < rightindex); CHECK_NOT_END(leftblock); @@ -981,8 +980,7 @@ deque_count(dequeobject *deque, PyObject *v) PyObject *item; int cmp; - n++; - while (--n) { + while (--n >= 0) { CHECK_NOT_END(b); item = b->data[index]; cmp = PyObject_RichCompareBool(item, v, Py_EQ); @@ -1019,8 +1017,7 @@ deque_contains(dequeobject *deque, PyObject *v) PyObject *item; int cmp; - n++; - while (--n) { + while (--n >= 0) { CHECK_NOT_END(b); item = b->data[index]; cmp = PyObject_RichCompareBool(item, v, Py_EQ); @@ -1088,13 +1085,13 @@ deque_index(dequeobject *deque, PyObject **args, Py_ssize_t nargs) } } - n = stop - i + 1; - while (--n) { + n = stop - i; + while (--n >= 0) { CHECK_NOT_END(b); item = b->data[index]; cmp = PyObject_RichCompareBool(item, v, Py_EQ); if (cmp > 0) - return PyLong_FromSsize_t(stop - n); + return PyLong_FromSsize_t(stop - n - 1); if (cmp < 0) return NULL; if (start_state != deque->state) { @@ -1228,16 +1225,14 @@ deque_item(dequeobject *deque, Py_ssize_t i) i = (Py_ssize_t)((size_t) i % BLOCKLEN); if (index < (Py_SIZE(deque) >> 1)) { b = deque->leftblock; - n++; - while (--n) + while (--n >= 0) b = b->rightlink; } else { n = (Py_ssize_t)( ((size_t)(deque->leftindex + Py_SIZE(deque) - 1)) / BLOCKLEN - n); b = deque->rightblock; - n++; - while (--n) + while (--n >= 0) b = b->leftlink; } } @@ -1281,16 +1276,14 @@ deque_ass_item(dequeobject *deque, Py_ssize_t i, PyObject *v) i = (Py_ssize_t)((size_t) i % BLOCKLEN); if (index <= halflen) { b = deque->leftblock; - n++; - while (--n) + while (--n >= 0) b = b->rightlink; } else { n = (Py_ssize_t)( ((size_t)(deque->leftindex + Py_SIZE(deque) - 1)) / BLOCKLEN - n); b = deque->rightblock; - n++; - while (--n) + while (--n >= 0) b = b->leftlink; } Py_INCREF(v); |