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