From: Pip Cet <pipcet@gmail.com>
To: emacs-devel@gnu.org, Paul Eggert <eggert@cs.ucla.edu>
Subject: Re: master b467bb5 4/4: Minimize ‘equal’ calls in (delete x vector)
Date: Sat, 15 Aug 2020 19:00:09 +0000 [thread overview]
Message-ID: <CAOqdjBc9RbLHYWje5cEJ6BEjvj+mnCUGMd9eo+P8NRi9g-ev+Q@mail.gmail.com> (raw)
In-Reply-To: <20200815181959.E7DC3209AC@vcs0.savannah.gnu.org>
On Sat, Aug 15, 2020 at 6:20 PM Paul Eggert <eggert@cs.ucla.edu> wrote:
>
> branch: master
> commit b467bb531e1ab0eed57e1889004d2115e80e4292
> Author: Paul Eggert <eggert@cs.ucla.edu>
> Commit: Paul Eggert <eggert@cs.ucla.edu>
>
> Minimize ‘equal’ calls in (delete x vector)
>
> * src/fns.c (Fdelete): When deleting from a vector, call Fequal
> only once per vector element. This is faster when Fequal is slow,
> and avoids the need to preinitialize the vector result. Finish
> when the result is exhausted, not when the input is exhausted;
> the two are equivalent but the former may be faster.
> * test/src/fns-tests.el (test-vector-delete): New test.
> ---
> src/fns.c | 38 +++++++++++++++++++++++++++++---------
> test/src/fns-tests.el | 5 +++++
> 2 files changed, 34 insertions(+), 9 deletions(-)
>
> diff --git a/src/fns.c b/src/fns.c
> index c89bd81..069edbe 100644
> --- a/src/fns.c
> +++ b/src/fns.c
> @@ -1747,22 +1747,42 @@ changing the value of a sequence `foo'. */)
> {
> if (VECTORP (seq))
> {
> - ptrdiff_t i, n;
> + ptrdiff_t n = 0;
> + ptrdiff_t size = ASIZE (seq);
> + ptrdiff_t neqbits_words = ((size + BITS_PER_BITS_WORD - 1)
> + / BITS_PER_BITS_WORD);
> + USE_SAFE_ALLOCA;
> + bits_word *neqbits = SAFE_ALLOCA (neqbits_words * sizeof *neqbits);
> + bits_word neqword = 0;
>
> - for (i = n = 0; i < ASIZE (seq); ++i)
> - if (NILP (Fequal (AREF (seq, i), elt)))
> - ++n;
This code looks wrong to me:
> + for (ptrdiff_t i = 0; i < size; i++)
> + {
> + bool neq = NILP (Fequal (AREF (seq, i), elt));
> + n += neq;
> + neqbits[i / BITS_PER_BITS_WORD] = neqword = (neqword << 1) + neq;
> + }
That left-shifts the first sequence element's bit left by up to 63
times. But ...
> + for (ptrdiff_t i = 0; ; i++)
> + if (neqbits[i / BITS_PER_BITS_WORD]
> + & ((bits_word) 1 << (i % BITS_PER_BITS_WORD)))
this checks the non-left-shifted LSB for the first sequence element.
Indeed, we have
(delete t [nil t]) => [t]
which is nonsensical.
next parent reply other threads:[~2020-08-15 19:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20200815181956.27401.76683@vcs0.savannah.gnu.org>
[not found] ` <20200815181959.E7DC3209AC@vcs0.savannah.gnu.org>
2020-08-15 19:00 ` Pip Cet [this message]
2020-08-15 19:22 ` master b467bb5 4/4: Minimize ‘equal’ calls in (delete x vector) Pip Cet
2020-08-15 19:42 ` Paul Eggert
2020-08-15 20:21 ` Pip Cet
2020-08-16 0:49 ` Paul Eggert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOqdjBc9RbLHYWje5cEJ6BEjvj+mnCUGMd9eo+P8NRi9g-ev+Q@mail.gmail.com \
--to=pipcet@gmail.com \
--cc=eggert@cs.ucla.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).