summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2022-12-16 11:08:02 +0100
committerMattias EngdegÄrd <mattiase@acm.org>2022-12-19 13:19:09 +0100
commit91d6b734216ed95f99f1f82ec6c1afd54af1c4dd (patch)
tree932ec96bc7d70ca79235baa2aa421e9122f7c099 /lisp/emacs-lisp
parent7f00dbe81a47d0b4dd18d28ebd18eb1448e8e377 (diff)
downloademacs-91d6b734216ed95f99f1f82ec6c1afd54af1c4dd.tar.gz
emacs-91d6b734216ed95f99f1f82ec6c1afd54af1c4dd.tar.bz2
emacs-91d6b734216ed95f99f1f82ec6c1afd54af1c4dd.zip
alist-get testfn argument evaluation correction
* lisp/emacs-lisp/gv.el (alist-get): Evaluate TESTFN exactly once (previously up to 3 times). Reduce the macro-expansion to include a call to either assoc or assq, not both; this reduces the generated code size in some cases.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r--lisp/emacs-lisp/gv.el6
1 files changed, 3 insertions, 3 deletions
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index 11251d7a963..48bc0269f36 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -417,9 +417,9 @@ The return value is the last VAL in the list.
(lambda (do key alist &optional default remove testfn)
(macroexp-let2 macroexp-copyable-p k key
(gv-letplace (getter setter) alist
- (macroexp-let2 nil p `(if (and ,testfn (not (eq ,testfn 'eq)))
- (assoc ,k ,getter ,testfn)
- (assq ,k ,getter))
+ (macroexp-let2 nil p (if (member testfn '(nil 'eq #'eq))
+ `(assq ,k ,getter)
+ `(assoc ,k ,getter ,testfn))
(funcall do (if (null default) `(cdr ,p)
`(if ,p (cdr ,p) ,default))
(lambda (v)