Code clean-up. Remove unnecessary pre-increment before the loop starts. (#3312)

This commit is contained in:
Raymond Hettinger 2017-09-04 16:07:06 -07:00 committed by GitHub
parent af64aff9f7
commit e1b0287c04
1 changed files with 10 additions and 17 deletions

View File

@ -938,8 +938,7 @@ deque_reverse(dequeobject *deque, PyObject *unused)
Py_ssize_t n = Py_SIZE(deque) >> 1; Py_ssize_t n = Py_SIZE(deque) >> 1;
PyObject *tmp; PyObject *tmp;
n++; while (--n >= 0) {
while (--n) {
/* Validate that pointers haven't met in the middle */ /* Validate that pointers haven't met in the middle */
assert(leftblock != rightblock || leftindex < rightindex); assert(leftblock != rightblock || leftindex < rightindex);
CHECK_NOT_END(leftblock); CHECK_NOT_END(leftblock);
@ -981,8 +980,7 @@ deque_count(dequeobject *deque, PyObject *v)
PyObject *item; PyObject *item;
int cmp; int cmp;
n++; while (--n >= 0) {
while (--n) {
CHECK_NOT_END(b); CHECK_NOT_END(b);
item = b->data[index]; item = b->data[index];
cmp = PyObject_RichCompareBool(item, v, Py_EQ); cmp = PyObject_RichCompareBool(item, v, Py_EQ);
@ -1019,8 +1017,7 @@ deque_contains(dequeobject *deque, PyObject *v)
PyObject *item; PyObject *item;
int cmp; int cmp;
n++; while (--n >= 0) {
while (--n) {
CHECK_NOT_END(b); CHECK_NOT_END(b);
item = b->data[index]; item = b->data[index];
cmp = PyObject_RichCompareBool(item, v, Py_EQ); 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; n = stop - i;
while (--n) { while (--n >= 0) {
CHECK_NOT_END(b); CHECK_NOT_END(b);
item = b->data[index]; item = b->data[index];
cmp = PyObject_RichCompareBool(item, v, Py_EQ); cmp = PyObject_RichCompareBool(item, v, Py_EQ);
if (cmp > 0) if (cmp > 0)
return PyLong_FromSsize_t(stop - n); return PyLong_FromSsize_t(stop - n - 1);
if (cmp < 0) if (cmp < 0)
return NULL; return NULL;
if (start_state != deque->state) { 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); i = (Py_ssize_t)((size_t) i % BLOCKLEN);
if (index < (Py_SIZE(deque) >> 1)) { if (index < (Py_SIZE(deque) >> 1)) {
b = deque->leftblock; b = deque->leftblock;
n++; while (--n >= 0)
while (--n)
b = b->rightlink; b = b->rightlink;
} else { } else {
n = (Py_ssize_t)( n = (Py_ssize_t)(
((size_t)(deque->leftindex + Py_SIZE(deque) - 1)) ((size_t)(deque->leftindex + Py_SIZE(deque) - 1))
/ BLOCKLEN - n); / BLOCKLEN - n);
b = deque->rightblock; b = deque->rightblock;
n++; while (--n >= 0)
while (--n)
b = b->leftlink; 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); i = (Py_ssize_t)((size_t) i % BLOCKLEN);
if (index <= halflen) { if (index <= halflen) {
b = deque->leftblock; b = deque->leftblock;
n++; while (--n >= 0)
while (--n)
b = b->rightlink; b = b->rightlink;
} else { } else {
n = (Py_ssize_t)( n = (Py_ssize_t)(
((size_t)(deque->leftindex + Py_SIZE(deque) - 1)) ((size_t)(deque->leftindex + Py_SIZE(deque) - 1))
/ BLOCKLEN - n); / BLOCKLEN - n);
b = deque->rightblock; b = deque->rightblock;
n++; while (--n >= 0)
while (--n)
b = b->leftlink; b = b->leftlink;
} }
Py_INCREF(v); Py_INCREF(v);