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) ...@@ -1045,6 +1045,9 @@ deque_clear(dequeobject *deque)
Py_ssize_t n; Py_ssize_t n;
PyObject *item; PyObject *item;
if (Py_SIZE(deque) == 0)
return;
/* During the process of clearing a deque, decrefs can cause the /* During the process of clearing a deque, decrefs can cause the
deque to mutate. To avoid fatal confusion, we have to make the deque to mutate. To avoid fatal confusion, we have to make the
deque empty before clearing the blocks and never refer to deque empty before clearing the blocks and never refer to
...@@ -1423,7 +1426,8 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs) ...@@ -1423,7 +1426,8 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
} }
} }
deque->maxlen = maxlen; deque->maxlen = maxlen;
deque_clear(deque); if (Py_SIZE(deque) > 0)
deque_clear(deque);
if (iterable != NULL) { if (iterable != NULL) {
PyObject *rv = deque_extend(deque, iterable); PyObject *rv = deque_extend(deque, iterable);
if (rv == NULL) if (rv == NULL)
......
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