]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6
authorRaymond Hettinger <python@rcn.com>
Wed, 7 Oct 2015 03:12:02 +0000 (23:12 -0400)
committerRaymond Hettinger <python@rcn.com>
Wed, 7 Oct 2015 03:12:02 +0000 (23:12 -0400)
Modules/_collectionsmodule.c

index aa3cf5c06e41df2436801df6ddf0997cb2c1dac1..c5690ef09ef815a4e2d382f3da06c23b0f7dbd04 100644 (file)
@@ -651,6 +651,9 @@ deque_clear(dequeobject *deque)
     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
@@ -1083,7 +1086,8 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
         }
     }
     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)