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'.
This commit is contained in:
parent
dd0dd87e3a
commit
f60fc1287d
7 changed files with 16 additions and 22 deletions
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -528,11 +528,10 @@ nested folders within them."
|
|||
(let* ((folder (mh-normalize-folder-name folder nil
|
||||
(string= folder "+/")
|
||||
t))
|
||||
(match (gethash folder mh-sub-folders-cache 'no-result))
|
||||
(sub-folders (cond ((eq match 'no-result)
|
||||
(setf (gethash folder mh-sub-folders-cache)
|
||||
(mh-sub-folders-actual folder)))
|
||||
(t match))))
|
||||
(sub-folders (if (hash-table-contains-p folder mh-sub-folders-cache)
|
||||
(gethash folder mh-sub-folders-cache)
|
||||
(setf (gethash folder mh-sub-folders-cache)
|
||||
(mh-sub-folders-actual folder)))))
|
||||
(if add-trailing-slash-flag
|
||||
(mapcar (lambda (x)
|
||||
(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
|
|||
last-slash)
|
||||
(while (setq last-slash (mh-search-from-end ?/ parent))
|
||||
(setq parent (substring parent 0 last-slash))
|
||||
(unless (eq (gethash parent mh-sub-folders-cache 'none) 'none)
|
||||
(when (hash-table-contains-p parent mh-sub-folders-cache)
|
||||
(remhash parent mh-sub-folders-cache)
|
||||
(if one-ancestor-found
|
||||
(cl-return-from ancestor-found)
|
||||
|
|
|
@ -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."
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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"))
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Reference in a new issue