aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-22 05:22:12 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-22 05:25:20 +0100
commitbd37a3dcd67af8e0c96d05f59af2afd95c46f9c1 (patch)
tree368d06392e9685a13cd479d43fecb931d02c8893
parent3bd63047706cf7c65eb31daa1f005de8cc0ddbe5 (diff)
compat-26: Optimize assoc
-rw-r--r--compat-26.el17
1 files changed, 11 insertions, 6 deletions
diff --git a/compat-26.el b/compat-26.el
index 1a370c2..9c209dc 100644
--- a/compat-26.el
+++ b/compat-26.el
@@ -92,12 +92,17 @@ If you just want to check `major-mode', use `derived-mode-p'."
(compat-defun assoc (key alist &optional testfn) ;; <compat-tests:assoc>
"Handle the optional TESTFN."
:extended t
- (if testfn
- (catch 'found
- (dolist (ent alist)
- (when (funcall testfn (car ent) key)
- (throw 'found ent))))
- (assoc key alist)))
+ (cond
+ ((or (eq testfn #'eq)
+ (and (not testfn) (or (symbolp key) (integerp key)))) ;; eq_comparable_value
+ (assq key alist))
+ ((or (eq testfn #'equal) (not testfn))
+ (assoc key alist))
+ (t
+ (catch 'found
+ (dolist (ent alist)
+ (when (funcall testfn (car ent) key)
+ (throw 'found ent)))))))
(compat-defun alist-get (key alist &optional default remove testfn) ;; <compat-tests:alist-get>
"Handle optional argument TESTFN."