cpython (2.7): Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6

https://hg.python.org/cpython/rev/37aee118e1a3 changeset: 98578:37aee118e1a3 branch: 2.7 parent: 98572:60c44a09c5fc user: Raymond Hettinger <python@rcn.com> date: Tue Oct 06 23:12:02 2015 -0400 summary: Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6 files: Modules/_collectionsmodule.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c --- 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) -- Repository URL: https://hg.python.org/cpython

On Tue, Oct 6, 2015, at 19:12, raymond.hettinger wrote:
https://hg.python.org/cpython/rev/37aee118e1a3 changeset: 98578:37aee118e1a3 branch: 2.7 parent: 98572:60c44a09c5fc user: Raymond Hettinger <python@rcn.com> date: Tue Oct 06 23:12:02 2015 -0400 summary: Backport early-out 91259f061cfb to reduce the cost of bb1a2944bcb6
files: Modules/_collectionsmodule.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c --- a/Modules/_collectionsmodule.c +++ b/Modules/_collectionsmodule.c @@ -651,6 +651,9 @@ Py_ssize_t n; PyObject *item;
+ if (Py_SIZE(deque) == 0) + return; +
dequeue is not varsized in Python 2.7, so using Py_SIZE() is incorrect.

There's two instances in that file. On Thu, Nov 12, 2015, at 07:20, Raymond Hettinger wrote:
On Nov 11, 2015, at 10:50 PM, Benjamin Peterson <benjamin@python.org> wrote:
+ if (Py_SIZE(deque) == 0) + return; +
dequeue is not varsized in Python 2.7, so using Py_SIZE() is incorrect.
Fixed in a2a518b6ded4.
- if (Py_SIZE(deque) == 0) + if (deque->len == 0)
Raymond
participants (3)
-
Benjamin Peterson
-
Raymond Hettinger
-
raymond.hettinger