diff options
author | Raymond Hettinger <python@rcn.com> | 2015-09-26 09:14:50 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2015-09-26 09:14:50 (GMT) |
commit | c22eee6b5917568933bbfec2be1069a4340efd84 (patch) | |
tree | caa054f444db64cc8c7085bf93f6567e4543889a /Modules | |
parent | 7a84552c84867b548a72b20c177542e892c528f6 (diff) | |
download | cpython-c22eee6b5917568933bbfec2be1069a4340efd84.zip cpython-c22eee6b5917568933bbfec2be1069a4340efd84.tar.gz cpython-c22eee6b5917568933bbfec2be1069a4340efd84.tar.bz2 |
Precomputing the number iterations allows the inner-loop to be vectorizable.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_collectionsmodule.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 2dcdf8b..487c765 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -557,7 +557,7 @@ static void deque_clear(dequeobject *deque); static PyObject * deque_inplace_repeat(dequeobject *deque, Py_ssize_t n) { - Py_ssize_t i, size; + Py_ssize_t i, m, size; PyObject *seq; PyObject *rv; @@ -598,7 +598,11 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n) MARK_END(b->rightlink); deque->rightindex = -1; } - for ( ; i < n-1 && deque->rightindex != BLOCKLEN - 1 ; i++) { + m = n - 1 - i; + if (m > BLOCKLEN - 1 - deque->rightindex) + m = BLOCKLEN - 1 - deque->rightindex; + i += m; + while (m--) { deque->rightindex++; Py_INCREF(item); deque->rightblock->data[deque->rightindex] = item; |