diff options
author | Raymond Hettinger <python@rcn.com> | 2004-03-04 08:00:54 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2004-03-04 08:00:54 (GMT) |
commit | 6c79a518e70ea8e45e3287573d99c648ae3cb21b (patch) | |
tree | e22c9b8d201333684b750e20d581f90e9e76a41b /Modules/collectionsmodule.c | |
parent | 30e97dbe96b3feee5108ec4b65be0ce80db89624 (diff) | |
download | cpython-6c79a518e70ea8e45e3287573d99c648ae3cb21b.zip cpython-6c79a518e70ea8e45e3287573d99c648ae3cb21b.tar.gz cpython-6c79a518e70ea8e45e3287573d99c648ae3cb21b.tar.bz2 |
Special case endpoint access for speed.
Diffstat (limited to 'Modules/collectionsmodule.c')
-rw-r--r-- | Modules/collectionsmodule.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/Modules/collectionsmodule.c b/Modules/collectionsmodule.c index f7fb91f..ddc6f88 100644 --- a/Modules/collectionsmodule.c +++ b/Modules/collectionsmodule.c @@ -326,18 +326,26 @@ deque_item(dequeobject *deque, int i) return NULL; } - i += deque->leftindex; - n = i / BLOCKLEN; - i %= BLOCKLEN; - if (i < (deque->len >> 1)) { + if (i == 0) { + i = deque->leftindex; b = deque->leftblock; - while (n--) - b = b->rightlink; - } else { - n = (deque->leftindex + deque->len - 1) / BLOCKLEN - n; + } else if (i == deque->len - 1) { + i = deque->rightindex; b = deque->rightblock; - while (n--) - b = b->leftlink; + } else { + i += deque->leftindex; + n = i / BLOCKLEN; + i %= BLOCKLEN; + if (i < (deque->len >> 1)) { + b = deque->leftblock; + while (n--) + b = b->rightlink; + } else { + n = (deque->leftindex + deque->len - 1) / BLOCKLEN - n; + b = deque->rightblock; + while (n--) + b = b->leftlink; + } } item = b->data[i]; Py_INCREF(item); |