Subject: bug#78162: [PATCH] hash-table-contains-p: Avoid creating a symbol on every call

From: Rudolf Schlatte <[email-masked]>
Date: Sun, 11 May 2025 08:02:03 +0200

Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <[email-masked]> writes:

> [ Ideally, this function would be replaced with one which doesn't return
>   just `t` but an actual "handle" on the hash-table slot, so that we can
>   then access that slot without redoing the key lookup.  It would allow
>   doing thing like `push` or `incf` on a hash-table entry without
>   looking up the key twice.
>   But doing so without allocating an object is hard with the current
>   hash-table design (and would come with its own downsides).  ]

A micro-optimization could be for the hash table to remember the last
key lookup, so that something like this hits a fast path for the second
lookup of the same key:

(when (hash-table-contains-p key table)
  (push 'x (gethash table key)))