diff options
author | Louie Lu <louie.lu@hopebaytech.com> | 2017-02-24 03:59:49 (GMT) |
---|---|---|
committer | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2017-02-24 03:59:49 (GMT) |
commit | 357bad7101df196d7f4ea3dc6ed9a6436afb022c (patch) | |
tree | a733b279089ee8202980a144ea40ba447d711ff1 /Modules/_collectionsmodule.c | |
parent | abb3b8ad94d699c8560d94ee9bac9c917b382abe (diff) | |
download | cpython-357bad7101df196d7f4ea3dc6ed9a6436afb022c.zip cpython-357bad7101df196d7f4ea3dc6ed9a6436afb022c.tar.gz cpython-357bad7101df196d7f4ea3dc6ed9a6436afb022c.tar.bz2 |
bpo-29634: Reduce deque repeat execution when maxlen exist and size is not 1 (#255) (#255)
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r-- | Modules/_collectionsmodule.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c index 8615bf1..44e9e11 100644 --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -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) { |