diff options
author | Raymond Hettinger <python@rcn.com> | 2015-09-14 05:03:04 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-09-14 05:03:04 (GMT) |
commit | ad26225e1a62f32848669b09326835dfd0369a79 (patch) | |
tree | 9cfdfae9712bf681bf56c22afd4b90f68f73b912 /Modules/_collectionsmodule.c | |
parent | e4f3467df17873db60dd1e8daf61e0c629abb130 (diff) | |
download | cpython-ad26225e1a62f32848669b09326835dfd0369a79.zip cpython-ad26225e1a62f32848669b09326835dfd0369a79.tar.gz cpython-ad26225e1a62f32848669b09326835dfd0369a79.tar.bz2 |
Tighten inner-loop for deque_inplace_repeat().
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 49a46a1..087f8e5 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -568,7 +568,7 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n) return PyErr_NoMemory(); deque->state++; - for (i = 0 ; i < n-1 ; i++) { + for (i = 0 ; i < n-1 ; ) { if (deque->rightindex == BLOCKLEN - 1) { block *b = newblock(Py_SIZE(deque) + i); if (b == NULL) { @@ -582,9 +582,11 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n) MARK_END(b->rightlink); deque->rightindex = -1; } - deque->rightindex++; - Py_INCREF(item); - deque->rightblock->data[deque->rightindex] = item; + for ( ; i < n-1 && deque->rightindex != BLOCKLEN - 1 ; i++) { + deque->rightindex++; + Py_INCREF(item); + deque->rightblock->data[deque->rightindex] = item; + } } Py_SIZE(deque) += i; Py_INCREF(deque); |