diff options
| author | Stefan Kangas | 2025-03-29 13:50:21 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2025-03-29 14:59:44 +0100 |
| commit | f60fc1287d499e8c93857b1b96e8bd2467b22c8d (patch) | |
| tree | 972126c3db11b14f93b352d698fd450fdddc2953 | |
| parent | dd0dd87e3aaf3116c400fba858cbe35ced15f04e (diff) | |
| download | emacs-f60fc1287d499e8c93857b1b96e8bd2467b22c8d.tar.gz emacs-f60fc1287d499e8c93857b1b96e8bd2467b22c8d.zip | |
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'.
| -rw-r--r-- | lisp/emacs-lisp/map.el | 3 | ||||
| -rw-r--r-- | lisp/external-completion.el | 9 | ||||
| -rw-r--r-- | lisp/mh-e/mh-utils.el | 11 | ||||
| -rw-r--r-- | lisp/net/ange-ftp.el | 2 | ||||
| -rw-r--r-- | lisp/password-cache.el | 6 | ||||
| -rw-r--r-- | lisp/pcmpl-x.el | 2 | ||||
| -rw-r--r-- | lisp/xdg.el | 5 |
7 files changed, 16 insertions, 22 deletions
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'." | |||
| 403 | 403 | ||
| 404 | (cl-defmethod map-contains-key ((map hash-table) key &optional _testfn) | 404 | (cl-defmethod map-contains-key ((map hash-table) key &optional _testfn) |
| 405 | "Return non-nil if MAP contains KEY, ignoring TESTFN." | 405 | "Return non-nil if MAP contains KEY, ignoring TESTFN." |
| 406 | (let ((v '(nil))) | 406 | (hash-table-contains-p key map)) |
| 407 | (not (eq v (gethash key map v))))) | ||
| 408 | 407 | ||
| 409 | (cl-defgeneric map-some (pred map) | 408 | (cl-defgeneric map-some (pred map) |
| 410 | "Return the first non-nil value from applying PRED to elements of MAP. | 409 | "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 be978f8f605..a1aa7ec9cb6 100644 --- a/lisp/external-completion.el +++ b/lisp/external-completion.el | |||
| @@ -117,11 +117,10 @@ EXPANDED-PATTERN." | |||
| 117 | completion-category-defaults))) | 117 | completion-category-defaults))) |
| 118 | (let ((cache (make-hash-table :test #'equal))) | 118 | (let ((cache (make-hash-table :test #'equal))) |
| 119 | (cl-flet ((lookup-internal (string point) | 119 | (cl-flet ((lookup-internal (string point) |
| 120 | (let* ((key (cons string point)) | 120 | (let ((key (cons string point))) |
| 121 | (probe (gethash key cache 'external--notfound))) | 121 | (if (hash-table-contains-p key cache) |
| 122 | (if (eq probe 'external--notfound) | 122 | (gethash key cache) |
| 123 | (puthash key (funcall lookup string point) cache) | 123 | (puthash key (funcall lookup string point) cache))))) |
| 124 | probe)))) | ||
| 125 | (lambda (string pred action) | 124 | (lambda (string pred action) |
| 126 | (pcase action | 125 | (pcase action |
| 127 | (`metadata | 126 | (`metadata |
diff --git a/lisp/mh-e/mh-utils.el b/lisp/mh-e/mh-utils.el index 5b8c48308ae..b330f73f7d2 100644 --- a/lisp/mh-e/mh-utils.el +++ b/lisp/mh-e/mh-utils.el | |||
| @@ -528,11 +528,10 @@ nested folders within them." | |||
| 528 | (let* ((folder (mh-normalize-folder-name folder nil | 528 | (let* ((folder (mh-normalize-folder-name folder nil |
| 529 | (string= folder "+/") | 529 | (string= folder "+/") |
| 530 | t)) | 530 | t)) |
| 531 | (match (gethash folder mh-sub-folders-cache 'no-result)) | 531 | (sub-folders (if (hash-table-contains-p folder mh-sub-folders-cache) |
| 532 | (sub-folders (cond ((eq match 'no-result) | 532 | (gethash folder mh-sub-folders-cache) |
| 533 | (setf (gethash folder mh-sub-folders-cache) | 533 | (setf (gethash folder mh-sub-folders-cache) |
| 534 | (mh-sub-folders-actual folder))) | 534 | (mh-sub-folders-actual folder))))) |
| 535 | (t match)))) | ||
| 536 | (if add-trailing-slash-flag | 535 | (if add-trailing-slash-flag |
| 537 | (mapcar (lambda (x) | 536 | (mapcar (lambda (x) |
| 538 | (if (cdr x) (cons (concat (car x) "/") (cdr x)) x)) | 537 | (if (cdr x) (cons (concat (car x) "/") (cdr x)) x)) |
| @@ -629,7 +628,7 @@ otherwise completion on +foo won't tell us about the option | |||
| 629 | last-slash) | 628 | last-slash) |
| 630 | (while (setq last-slash (mh-search-from-end ?/ parent)) | 629 | (while (setq last-slash (mh-search-from-end ?/ parent)) |
| 631 | (setq parent (substring parent 0 last-slash)) | 630 | (setq parent (substring parent 0 last-slash)) |
| 632 | (unless (eq (gethash parent mh-sub-folders-cache 'none) 'none) | 631 | (when (hash-table-contains-p parent mh-sub-folders-cache) |
| 633 | (remhash parent mh-sub-folders-cache) | 632 | (remhash parent mh-sub-folders-cache) |
| 634 | (if one-ancestor-found | 633 | (if one-ancestor-found |
| 635 | (cl-return-from ancestor-found) | 634 | (cl-return-from ancestor-found) |
diff --git a/lisp/net/ange-ftp.el b/lisp/net/ange-ftp.el index 84e170987ef..3d7ce0add48 100644 --- a/lisp/net/ange-ftp.el +++ b/lisp/net/ange-ftp.el | |||
| @@ -1004,7 +1004,7 @@ or nil meaning don't change it." | |||
| 1004 | 1004 | ||
| 1005 | (defun ange-ftp-hash-entry-exists-p (key tbl) | 1005 | (defun ange-ftp-hash-entry-exists-p (key tbl) |
| 1006 | "Return whether there is an association for KEY in table TBL." | 1006 | "Return whether there is an association for KEY in table TBL." |
| 1007 | (and tbl (not (eq (gethash key tbl 'unknown) 'unknown)))) | 1007 | (and tbl (hash-table-contains-p key tbl))) |
| 1008 | 1008 | ||
| 1009 | (defun ange-ftp-hash-table-keys (tbl) | 1009 | (defun ange-ftp-hash-table-keys (tbl) |
| 1010 | "Return a sorted list of all the active keys in table TBL, as strings." | 1010 | "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." | |||
| 82 | "Check if KEY is in the cache." | 82 | "Check if KEY is in the cache." |
| 83 | (and password-cache | 83 | (and password-cache |
| 84 | key | 84 | key |
| 85 | (not (eq (gethash key password-data 'password-cache-no-data) | 85 | (hash-table-contains-p key password-data))) |
| 86 | 'password-cache-no-data)))) | ||
| 87 | 86 | ||
| 88 | (defun password-read (prompt &optional key) | 87 | (defun password-read (prompt &optional key) |
| 89 | "Read password, for use with KEY, from user, or from cache if wanted. | 88 | "Read password, for use with KEY, from user, or from cache if wanted. |
| @@ -110,8 +109,7 @@ user again." | |||
| 110 | "Add password to cache. | 109 | "Add password to cache. |
| 111 | The password is removed by a timer after `password-cache-expiry' seconds." | 110 | The password is removed by a timer after `password-cache-expiry' seconds." |
| 112 | (when (and password-cache-expiry | 111 | (when (and password-cache-expiry |
| 113 | (eq (gethash key password-data 'password-cache-no-data) | 112 | (not (hash-table-contains-p key password-data))) |
| 114 | 'password-cache-no-data)) | ||
| 115 | (run-at-time password-cache-expiry nil | 113 | (run-at-time password-cache-expiry nil |
| 116 | #'password-cache-remove | 114 | #'password-cache-remove |
| 117 | key)) | 115 | 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 @@ | |||
| 121 | 121 | ||
| 122 | (defun pcmpl-x-tlmgr-action-options (action) | 122 | (defun pcmpl-x-tlmgr-action-options (action) |
| 123 | "Get the list of long options for ACTION." | 123 | "Get the list of long options for ACTION." |
| 124 | (if (eq (gethash action pcmpl-x-tlmgr-options-cache 'missing) 'missing) | 124 | (if (not (hash-table-contains-p action pcmpl-x-tlmgr-options-cache)) |
| 125 | (with-temp-buffer | 125 | (with-temp-buffer |
| 126 | (when (zerop | 126 | (when (zerop |
| 127 | (call-process pcmpl-x-tlmgr-program nil t nil action "-h")) | 127 | (call-process pcmpl-x-tlmgr-program nil t nil action "-h")) |
diff --git a/lisp/xdg.el b/lisp/xdg.el index 8bb5ee71457..a9f443c3d73 100644 --- a/lisp/xdg.el +++ b/lisp/xdg.el | |||
| @@ -384,9 +384,8 @@ Results are cached in `xdg-mime-table'." | |||
| 384 | (setq xdg-mime-table nil))) | 384 | (setq xdg-mime-table nil))) |
| 385 | (when (null (assoc type xdg-mime-table)) | 385 | (when (null (assoc type xdg-mime-table)) |
| 386 | (push (cons type (make-hash-table :test #'equal)) xdg-mime-table)) | 386 | (push (cons type (make-hash-table :test #'equal)) xdg-mime-table)) |
| 387 | (if (let ((def (make-symbol "def")) | 387 | (if (let ((table (cdr (assoc type xdg-mime-table)))) |
| 388 | (table (cdr (assoc type xdg-mime-table)))) | 388 | (hash-table-contains-p subtype table)) |
| 389 | (not (eq (setq files (gethash subtype table def)) def))) | ||
| 390 | files | 389 | files |
| 391 | (and files (setq files nil)) | 390 | (and files (setq files nil)) |
| 392 | (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) | 391 | (let ((dirs (mapcar (lambda (dir) (expand-file-name "applications" dir)) |