Commit 26a52c6e authored by Raymond Hettinger's avatar Raymond Hettinger

Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6

parent 19f5e10f
......@@ -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,6 +1426,7 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
}
}
deque->maxlen = maxlen;
if (Py_SIZE(deque) > 0)
deque_clear(deque);
if (iterable != NULL) {
PyObject *rv = deque_extend(deque, iterable);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment