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;
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);