emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat bd37a3dcd6 4/5: compat-26: Optimize assoc


From: ELPA Syncer
Subject: [elpa] externals/compat bd37a3dcd6 4/5: compat-26: Optimize assoc
Date: Sat, 21 Jan 2023 23:57:26 -0500 (EST)

branch: externals/compat
commit bd37a3dcd67af8e0c96d05f59af2afd95c46f9c1
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-26: Optimize assoc
---
 compat-26.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/compat-26.el b/compat-26.el
index 1a370c20cc..9c209dce13 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."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]