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

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 12 May 2025 21:22:02 +0000

Your bug report

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

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
78162: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=78162
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#78162: [PATCH] hash-table-contains-p: Avoid creating a symbol on every call
From: Stefan Monnier <[email-masked]>
To: Pip Cet <[email-masked]>
Cc: Daniel Mendler <[email-masked]>, [email-masked], Stefan Kangas <[email-masked]>
Date: Mon, 12 May 2025 17:20:54 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

>> Then an alternative would be the simpler patch below?
> I tried hard to find something wrong with it, but couldn't.

Push to `master`, closing,

        Stefan

Subject: [PATCH] hash-table-contains-p: Avoid creating a symbol on every call
From: Daniel Mendler <[email-masked]>
To: [email-masked]
Cc: Stefan Kangas <[email-masked]>
Date: Wed, 30 Apr 2025 12:03:27 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

For performance reasons avoid creating a symbol on every call to
`hash-table-contains-p'.  See also https://github.com/emacs-compat/compat/issues/71.

>From b5a16167a27a355b506d53655816b0c22979acf7 Mon Sep 17 00:00:00 2001
From: Daniel Mendler <[email-masked]>
Date: Wed, 30 Apr 2025 12:00:59 +0200
Subject: [PATCH] hash-table-contains-p: Avoid creating a symbol on every call

For performance reasons avoid creating a symbol on every call to
`hash-table-contains-p'.

lisp/subr.el (hash-table--missing): New symbol.
(hash-table-contains-p): Use it.
---
 lisp/subr.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index a5c850ebe5e..892ddfaa66a 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -7436,12 +7436,12 @@ string-trim
   (declare (important-return-value t))
   (string-trim-left (string-trim-right string trim-right) trim-left))
 
+(defconst hash-table--missing (make-symbol "hash-table--missing"))
 (defsubst hash-table-contains-p (key table)
   "Return non-nil if TABLE has an element with KEY."
   (declare (side-effect-free t)
            (important-return-value t))
-  (let ((missing (make-symbol "missing")))
-    (not (eq (gethash key table missing) missing))))
+  (not (eq (gethash key table hash-table--missing) hash-table--missing)))
 
 ;; The initial anchoring is for better performance in searching matches.
 (defconst regexp-unmatchable "\\`a\\`"
-- 
2.47.2