]> granicus.if.org Git - python/commitdiff
Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6
authorRaymond Hettinger <python@rcn.com>
Wed, 7 Oct 2015 03:06:17 +0000 (23:06 -0400)
committerRaymond Hettinger <python@rcn.com>
Wed, 7 Oct 2015 03:06:17 +0000 (23:06 -0400)
Modules/_collectionsmodule.c

index 5dea8cbbd1728851e49132a40271cce4e75e3967..66f5939c60e1fab85dee022c19743271323b3bfa 100644 (file)
@@ -1045,6 +1045,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
@@ -1423,7 +1426,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)