summaryrefslogtreecommitdiff
path: root/lisp/simple.el
diff options
context:
space:
mode:
authorMichael Heerdegen <michael_heerdegen@web.de>2022-09-18 12:26:53 +0200
committerMichael Heerdegen <michael_heerdegen@web.de>2022-10-09 20:42:44 +0200
commit93136169cba9c7c8f827dbc2f579b95a75d15fad (patch)
treebedeaf68b0077928c18ff166357056a69f85402a /lisp/simple.el
parent90c3a25eb112f9c2b3d5fe2b5697160f7df10324 (diff)
downloademacs-93136169cba9c7c8f827dbc2f579b95a75d15fad.tar.gz
Try to speed up extended command shorthand computation
Discussed in Bug#51143. * lisp/simple.el (execute-extended-command--shorter): Compute a complete list of `commandp' symbols once. This significantly speeds up complicated cases while the slowdown of simple cases is still accetable.
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el8
1 files changed, 6 insertions, 2 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index d2dcbe27a07..e804f717b01 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2465,9 +2465,13 @@ Also see `suggest-key-bindings'."
(defun execute-extended-command--shorter (name typed)
(let ((candidates '())
+ commands
(max (length typed))
(len 1)
binding)
+ ;; Precompute a list of commands once to avoid repeated `commandp' testing
+ ;; of symbols in the `completion-try-completion' call inside the loop below
+ (mapatoms (lambda (s) (when (commandp s) (push s commands))))
(while (and (not binding)
(progn
(unless candidates
@@ -2480,8 +2484,8 @@ Also see `suggest-key-bindings'."
(input-pending-p) ;Dummy call to trigger input-processing, bug#23002.
(let ((candidate (pop candidates)))
(when (equal name
- (car-safe (completion-try-completion
- candidate obarray 'commandp len)))
+ (car-safe (completion-try-completion
+ candidate commands nil len)))
(setq binding candidate))))
binding))