Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index aa3cf5c..c5690ef 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -651,6 +651,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
@@ -1083,7 +1086,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)