bpo-29634: Reduce deque repeat execution when maxlen exist and size is not 1 (#255) (#255)

This commit is contained in:
Louie Lu 2017-02-24 11:59:49 +08:00 committed by Raymond Hettinger
parent abb3b8ad94
commit 357bad7101
1 changed files with 4 additions and 0 deletions

View File

@ -731,6 +731,10 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
if (seq == NULL)
return seq;
/* Reduce the number of repetitions when maxlen would be exceeded */
if (deque->maxlen >= 0 && n * size > deque->maxlen)
n = (deque->maxlen + size - 1) / size;
for (i = 0 ; i < n-1 ; i++) {
rv = deque_extend(deque, seq);
if (rv == NULL) {