emacs-diffs
[Top][All Lists]
Advanced

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

master df99b17: Speed up completion-in-mode-p in the common case


From: Lars Ingebrigtsen
Subject: master df99b17: Speed up completion-in-mode-p in the common case
Date: Sun, 14 Feb 2021 22:23:04 -0500 (EST)

branch: master
commit df99b17e4fe7f6ee0c09ac990117ffea6ee3b695
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Speed up completion-in-mode-p in the common case
    
    * lisp/simple.el (completion-in-mode-p): Make predicate more
    efficient in the common one-mode case.
---
 lisp/simple.el | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 44a9c4d..ed0e753 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1978,15 +1978,20 @@ This function uses the 
`read-extended-command-predicate' user option."
   "Say whether SYMBOL should be offered as a completion.
 This is true if the command is applicable to the major mode in
 BUFFER, or any of the active minor modes in BUFFER."
-  (or (null (command-modes symbol))
-      ;; It's derived from a major mode.
-      (apply #'provided-mode-derived-p
-             (buffer-local-value 'major-mode buffer)
-             (command-modes symbol))
-      ;; It's a minor mode.
-      (seq-intersection (command-modes symbol)
-                        (buffer-local-value 'minor-modes buffer)
-                        #'eq)))
+  (let ((modes (command-modes symbol)))
+    (or (null modes)
+        ;; Common case: Just a single mode.
+        (if (null (cdr modes))
+            (or (provided-mode-derived-p
+                 (buffer-local-value 'major-mode buffer) (car modes))
+                (memq (car modes) (buffer-local-value 'minor-modes buffer)))
+          ;; Uncommon case: Multiple modes.
+          (apply #'provided-mode-derived-p
+                 (buffer-local-value 'major-mode buffer)
+                 modes)
+          (seq-intersection modes
+                            (buffer-local-value 'minor-modes buffer)
+                            #'eq)))))
 
 (defun completion-with-modes-p (modes buffer)
   "Say whether MODES are in action in BUFFER.



reply via email to

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