[Python-checkins] cpython (3.5): Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6

raymond.hettinger python-checkins at python.org
Tue Oct 6 23:08:17 EDT 2015


https://hg.python.org/cpython/rev/6fb0f26ed858
changeset:   98576:6fb0f26ed858
branch:      3.5
parent:      98574:e02e4afcce6a
user:        Raymond Hettinger <python at rcn.com>
date:        Tue Oct 06 23:06:17 2015 -0400
summary:
  Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6

files:
  Modules/_collectionsmodule.c |  6 +++++-
  1 files changed, 5 insertions(+), 1 deletions(-)


diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -1045,6 +1045,9 @@
     Py_ssize_t n;
     PyObject *item;
 
+    if (Py_SIZE(deque) == 0)
+        return;
+
     /* During the process of clearing a deque, decrefs can cause the
        deque to mutate.  To avoid fatal confusion, we have to make the
        deque empty before clearing the blocks and never refer to
@@ -1423,7 +1426,8 @@
         }
     }
     deque->maxlen = maxlen;
-    deque_clear(deque);
+    if (Py_SIZE(deque) > 0)
+        deque_clear(deque);
     if (iterable != NULL) {
         PyObject *rv = deque_extend(deque, iterable);
         if (rv == NULL)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list