Skip to content

Commit 357bad7

Browse files
Louie Lurhettinger
authored andcommitted
bpo-29634: Reduce deque repeat execution when maxlen exist and size is not 1 (#255) (#255)
1 parent abb3b8a commit 357bad7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

Modules/_collectionsmodule.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,10 @@ deque_inplace_repeat(dequeobject *deque, Py_ssize_t n)
731731
if (seq == NULL)
732732
return seq;
733733

734+
/* Reduce the number of repetitions when maxlen would be exceeded */
735+
if (deque->maxlen >= 0 && n * size > deque->maxlen)
736+
n = (deque->maxlen + size - 1) / size;
737+
734738
for (i = 0 ; i < n-1 ; i++) {
735739
rv = deque_extend(deque, seq);
736740
if (rv == NULL) {

0 commit comments

Comments
 (0)