From: Stefan Kangas Date: Sat, 29 Mar 2025 12:50:21 +0000 (+0100) Subject: Use 'hash-table-contains-p' in a few places X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4dd74be85219d961a08db6c5aa724f27607b3428;p=emacs.git Use 'hash-table-contains-p' in a few places This replaces open coded versions of the common idiom (not (eq (gethash key table 'missing) 'missing)) with (hash-table-contains-p key table) in files where we can rely on features in Emacs 31. * lisp/emacs-lisp/map.el (map-contains-key): * lisp/external-completion.el (external-completion-table): * lisp/mh-e/mh-utils.el (mh-sub-folders) (mh-remove-from-sub-folders-cache): * lisp/net/ange-ftp.el (ange-ftp-hash-entry-exists-p): * lisp/password-cache.el (password-in-cache-p, password-cache-add): * lisp/pcmpl-x.el (pcmpl-x-tlmgr-action-options): * lisp/xdg.el (xdg-mime-apps): Use 'hash-table-contains-p'. (cherry picked from commit f60fc1287d499e8c93857b1b96e8bd2467b22c8d) --- diff --git a/lisp/emacs-lisp/map.el b/lisp/emacs-lisp/map.el index 72ff5e2221d..deeeec132cf 100644 --- a/lisp/emacs-lisp/map.el +++ b/lisp/emacs-lisp/map.el @@ -403,8 +403,7 @@ If MAP is a plist, TESTFN defaults to `eq'." (cl-defmethod map-contains-key ((map hash-table) key &optional _testfn) "Return non-nil if MAP contains KEY, ignoring TESTFN." - (let ((v '(nil))) - (not (eq v (gethash key map v))))) + (hash-table-contains-p key map)) (cl-defgeneric map-some (pred map) "Return the first non-nil value from applying PRED to elements of MAP. diff --git a/lisp/external-completion.el b/lisp/external-completion.el index 6f9b450eb4d..a136674e869 100644 --- a/lisp/external-completion.el +++ b/lisp/external-completion.el @@ -117,11 +117,10 @@ EXPANDED-PATTERN." completion-category-defaults))) (let ((cache (make-hash-table :test #'equal))) (cl-flet ((lookup-internal (string point) - (let* ((key (cons string point)) - (probe (gethash key cache 'external--notfound))) - (if (eq probe 'external--notfound) - (puthash key (funcall lookup string point) cache) - probe)))) + (let ((key (cons string point))) + (if (hash-table-contains-p key cache) + (gethash key cache) + (puthash key (funcall lookup string point) cache))))) (lambda (string pred action) (pcase action (`metadata diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index ad1011cb5d8..5c9d3d3ebfd 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el @@ -1004,7 +1004,7 @@ or nil meaning don't change it." (defun ange-ftp-hash-entry-exists-p (key tbl) "Return whether there is an association for KEY in table TBL." - (and tbl (not (eq (gethash key tbl 'unknown) 'unknown)))) + (and tbl (hash-table-contains-p key tbl))) (defun ange-ftp-hash-table-keys (tbl) "Return a sorted list of all the active keys in table TBL, as strings." diff --git a/lisp/password-cache.el b/lisp/password-cache.el index 46c04789c00..5701ac7df66 100644 --- a/lisp/password-cache.el +++ b/lisp/password-cache.el @@ -82,8 +82,7 @@ regulate cache behavior." "Check if KEY is in the cache." (and password-cache key - (not (eq (gethash key password-data 'password-cache-no-data) - 'password-cache-no-data)))) + (hash-table-contains-p key password-data))) (defun password-read (prompt &optional key) "Read password, for use with KEY, from user, or from cache if wanted. @@ -110,8 +109,7 @@ user again." "Add password to cache. The password is removed by a timer after `password-cache-expiry' seconds." (when (and password-cache-expiry - (eq (gethash key password-data 'password-cache-no-data) - 'password-cache-no-data)) + (not (hash-table-contains-p key password-data))) (run-at-time password-cache-expiry nil #'password-cache-remove key)) diff --git a/lisp/pcmpl-x.el b/lisp/pcmpl-x.el index 578e8a362a3..dbd8600a2e7 100644 --- a/lisp/pcmpl-x.el +++ b/lisp/pcmpl-x.el @@ -121,7 +121,7 @@ (defun pcmpl-x-tlmgr-action-options (action) "Get the list of long options for ACTION." - (if (eq (gethash action pcmpl-x-tlmgr-options-cache 'missing) 'missing) + (if (not (hash-table-contains-p action pcmpl-x-tlmgr-options-cache)) (with-temp-buffer (when (zerop (call-process pcmpl-x-tlmgr-program nil t nil action "-h")) diff --git a/lisp/xdg.el b/lisp/xdg.el index 7f86c8eb8d0..5058fb13052 100644 --- a/lisp/xdg.el +++ b/lisp/xdg.el @@ -384,9 +384,8 @@ Results are cached in `xdg-mime-table'." (setq xdg-mime-table nil))) (when (null (assoc type xdg-mime-table)) (push (cons type (make-hash-table :test #'equal)) xdg-mime-table)) - (if (let ((def (make-symbol "def")) - (table (cdr (assoc type xdg-mime-table)))) - (not (eq (setq files (gethash subtype table def)) def))) + (if (let ((table (cdr (assoc type xdg-mime-table)))) + (hash-table-contains-p subtype table)) files (and files (setq files nil)) (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir))