unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@protonmail.com>
To: emacs-devel@gnu.org
Cc: Mattias Engdegard <mattiase@acm.org>
Subject: Re: master 46f3452b30f: Simplify and speed up make-hash-table argument parsing
Date: Wed, 21 Aug 2024 13:39:43 +0000	[thread overview]
Message-ID: <87ed6i9eqt.fsf@protonmail.com> (raw)
In-Reply-To: <20240821125036.5728AC1F9FB@vcs2.savannah.gnu.org>

Mattias Engdegård via Mailing list for Emacs changes <emacs-diffs@gnu.org> writes:

> branch: master
> commit 46f3452b30f39a69f610faab58c1490b34dd367d
> Author: Mattias Engdegård <mattiase@acm.org>
> Commit: Mattias Engdegård <mattiase@acm.org>
>
>     Simplify and speed up make-hash-table argument parsing
>
>     * src/fns.c (get_key_arg): Remove.
>     (Fmake_hash_table): Traverse argument list once only.  Don't allocate a
>     helper array.  Use faster comparisons.
> ---
>  src/fns.c | 112 +++++++++++++++++++++++---------------------------------------
>  1 file changed, 42 insertions(+), 70 deletions(-)
>
> diff --git a/src/fns.c b/src/fns.c
> index 80794bc73a0..80ae554c86e 100644
> --- a/src/fns.c
> +++ b/src/fns.c
> @@ -4637,30 +4637,6 @@ next_almost_prime (EMACS_INT n)
>        return n;
>  }
>
> -
> -/* Find KEY in ARGS which has size NARGS.  Don't consider indices for
> -   which USED[I] is non-zero.  If found at index I in ARGS, set
> -   USED[I] and USED[I + 1] to 1, and return I + 1.  Otherwise return
> -   0.  This function is used to extract a keyword/argument pair from
> -   a DEFUN parameter list.  */
> -
> -static ptrdiff_t
> -get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used)
> -{
> -  ptrdiff_t i;
> -
> -  for (i = 1; i < nargs; i++)
> -    if (!used[i - 1] && EQ (args[i - 1], key))
> -      {
> -	used[i - 1] = 1;
> -	used[i] = 1;
> -	return i;
> -      }
> -
> -  return 0;
> -}
> -
> -

This (removed) code used to accept calls such as

(make-hash-table :rehash-size :test 'eq)

which doesn't make sense, so we definitely should change something here.

>  /* Return a Lisp vector which has the same contents as VEC but has
>     at least INCR_MIN more entries, where INCR_MIN is positive.
>     If NITEMS_MAX is not -1, do not grow the vector to be any larger
> @@ -5762,32 +5738,43 @@ and ignored.
>  usage: (make-hash-table &rest KEYWORD-ARGS)  */)
>    (ptrdiff_t nargs, Lisp_Object *args)
>  {
> -  USE_SAFE_ALLOCA;
> +  Lisp_Object test_arg = Qnil;
> +  Lisp_Object weakness_arg = Qnil;
> +  Lisp_Object size_arg = Qnil;
> +  Lisp_Object purecopy_arg = Qnil;
> +
> +  if (nargs & 1)
> +    error ("Odd number of arguments");
> +  while (nargs >= 2)
> +    {
> +      Lisp_Object arg = maybe_remove_pos_from_symbol (args[--nargs]);
> +      Lisp_Object kw = maybe_remove_pos_from_symbol (args[--nargs]);
> +      if (BASE_EQ (kw, QCtest))

Is this really faster than not removing the position from the symbol in
the first place? (I must confess I don't like using BASE_EQ, we should
just use 'eassume' and let the compiler choose the faster
implementation, but that doesn't actually appear to work too well in
practice).

> +	test_arg = arg;
> +      else if (BASE_EQ (kw, QCweakness))
> +	weakness_arg = arg;
> +      else if (BASE_EQ (kw, QCsize))
> +	size_arg = arg;
> +      else if (BASE_EQ (kw, QCpurecopy))
> +	purecopy_arg = arg;
> +      else if (BASE_EQ (kw, QCrehash_threshold) || BASE_EQ (kw, QCrehash_size))
> +	;  /* ignore obsolete keyword arguments */
> +      else
> +	signal_error ("Invalid keyword argument", kw);
> +    }

The new code accepts duplicate arguments, such as

(make-hash-table :test 'eq :test 'eq)

Is that intentional, harmless, or undesirable?

Anyway, it'll be even simpler once we remove purespace :-)

Pip




       reply	other threads:[~2024-08-21 13:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <172424463538.7415.12172458876271190421@vcs2.savannah.gnu.org>
     [not found] ` <20240821125036.5728AC1F9FB@vcs2.savannah.gnu.org>
2024-08-21 13:39   ` Pip Cet [this message]
2024-08-21 14:03     ` master 46f3452b30f: Simplify and speed up make-hash-table argument parsing Mattias Engdegård

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=87ed6i9eqt.fsf@protonmail.com \
    --to=pipcet@protonmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.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).