[Python-checkins] cpython: In-line the append operations inside deque_inplace_repeat().

Brett Cannon bcannon at gmail.com
Mon Sep 14 18:49:15 CEST 2015


Would it be worth adding a comment that the block of code is an inlined
copy of deque_append()? Or maybe even turn the append() function into a
macro so you minimize code duplication?

On Sat, 12 Sep 2015 at 08:00 raymond.hettinger <python-checkins at python.org>
wrote:

> https://hg.python.org/cpython/rev/cb96ffe6ff10
> changeset:   97943:cb96ffe6ff10
> parent:      97941:b8f3a01937be
> user:        Raymond Hettinger <python at rcn.com>
> date:        Sat Sep 12 11:00:20 2015 -0400
> summary:
>   In-line the append operations inside deque_inplace_repeat().
>
> files:
>   Modules/_collectionsmodule.c |  22 ++++++++++++++++++----
>   1 files changed, 18 insertions(+), 4 deletions(-)
>
>
> diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
> --- a/Modules/_collectionsmodule.c
> +++ b/Modules/_collectionsmodule.c
> @@ -567,12 +567,26 @@
>          if (n > MAX_DEQUE_LEN)
>              return PyErr_NoMemory();
>
> +        deque->state++;
>          for (i = 0 ; i < n-1 ; i++) {
> -            rv = deque_append(deque, item);
> -            if (rv == NULL)
> -                return NULL;
> -            Py_DECREF(rv);
> +            if (deque->rightindex == BLOCKLEN - 1) {
> +                block *b = newblock(Py_SIZE(deque) + i);
> +                if (b == NULL) {
> +                    Py_SIZE(deque) += i;
> +                    return NULL;
> +                }
> +                b->leftlink = deque->rightblock;
> +                CHECK_END(deque->rightblock->rightlink);
> +                deque->rightblock->rightlink = b;
> +                deque->rightblock = b;
> +                MARK_END(b->rightlink);
> +                deque->rightindex = -1;
> +            }
> +            deque->rightindex++;
> +            Py_INCREF(item);
> +            deque->rightblock->data[deque->rightindex] = item;
>          }
> +        Py_SIZE(deque) += i;
>          Py_INCREF(deque);
>          return (PyObject *)deque;
>      }
>
> --
> Repository URL: https://hg.python.org/cpython
> _______________________________________________
> Python-checkins mailing list
> Python-checkins at python.org
> https://mail.python.org/mailman/listinfo/python-checkins
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-checkins/attachments/20150914/04ae156a/attachment.html>


More information about the Python-checkins mailing list