summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2015-10-07 03:06:17 (GMT)
committerRaymond Hettinger <python@rcn.com>2015-10-07 03:06:17 (GMT)
commit848f2b595d19ba784535d1ae38beb7413b1d51cd (patch)
tree207edb574cfe6ff082aa5d6ded64ac78fb216883
parent59dc696821da8888b5ac1b86c6c0fd4202f92b39 (diff)
downloadcpython-848f2b595d19ba784535d1ae38beb7413b1d51cd.zip
cpython-848f2b595d19ba784535d1ae38beb7413b1d51cd.tar.gz
cpython-848f2b595d19ba784535d1ae38beb7413b1d51cd.tar.bz2
Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6
-rw-r--r--Modules/_collectionsmodule.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 5dea8cb..66f5939 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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)