FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Heapq: Code clean-up. Remove unnecessary pre-increment before the loop starts. by rhettinger · Pull Request #3312 · python/cpython · GitHub

/ cpython Public
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 10 additions & 17 deletions Modules/_collectionsmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
Expand Down

Back | FazBrowse Home | New Git URL