aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Drozd <nicholasdrozd@gmail.com>2019-01-01 18:50:59 -0600
committerWilfred Hughes <me@wilfred.me.uk>2019-01-08 00:38:36 +0000
commitcfda60fdf2c8181ee2a96daf7d7a1c10d2f36eed (patch)
tree7fd23ceda83b07b7ee5e9d25cce3c902c630b8b2
parent2c6576f731282209492ca7c0217346deb9666785 (diff)
Cut repeated calls to helpful--aliases
helpful--aliases is expensive, so as usual we'll call it just once at the beginning of helpful-update. This sacrifices a little elegance for a significant peformance boost. Here are before and after times running (helpful-callable #'move-beginning-of-line) 50 times on my crappy little Thinkpad: Before: Elapsed time: 61.507899s (23.391894s in 148 GCs) Elapsed time: 56.855148s (24.392109s in 133 GCs) Elapsed time: 58.082409s (25.796263s in 146 GCs) After: Elapsed time: 43.519486s (17.412847s in 95 GCs) Elapsed time: 43.171007s (17.036012s in 92 GCs) Elapsed time: 44.725709s (18.705316s in 102 GCs) So the time per call goes from a little over a second to a little under a second.
-rw-r--r--helpful.el27
-rw-r--r--test/helpful-unit-test.el2
2 files changed, 14 insertions, 15 deletions
diff --git a/helpful.el b/helpful.el
index eee06f1..659e848 100644
--- a/helpful.el
+++ b/helpful.el
@@ -1380,22 +1380,21 @@ alist with the lists concatenated."
l1)))
(append l1-with-values l2-extra-values)))
-(defun helpful--keymaps-containing-aliases (command-sym)
+(defun helpful--keymaps-containing-aliases (command-sym aliases)
"Return a list of pairs mapping keymap symbols to the
keybindings for COMMAND-SYM in each keymap.
Includes keybindings for aliases, unlike
`helpful--keymaps-containing'."
- (let* ((aliases (helpful--aliases command-sym t))
- (syms (cons command-sym aliases))
+ (let* ((syms (cons command-sym aliases))
(syms-keymaps (-map #'helpful--keymaps-containing syms)))
(-reduce #'helpful--merge-alists syms-keymaps)))
-(defun helpful--format-keys (command-sym)
+(defun helpful--format-keys (command-sym aliases)
"Describe all the keys that call COMMAND-SYM."
(let (mode-lines
global-lines)
- (--each (helpful--keymaps-containing-aliases command-sym)
+ (--each (helpful--keymaps-containing-aliases command-sym aliases)
(-let [(map . keys) it]
(dolist (key keys)
(push
@@ -1862,7 +1861,8 @@ state of the current symbol."
(buffer-file-name buf)))
(references (helpful--calculate-references
helpful--sym helpful--callable-p
- source-path)))
+ source-path))
+ (aliases (helpful--aliases helpful--sym helpful--callable-p)))
(erase-buffer)
@@ -1963,7 +1963,7 @@ state of the current symbol."
(helpful--insert-section-break)
(insert
(helpful--heading "Key Bindings")
- (helpful--format-keys helpful--sym)))
+ (helpful--format-keys helpful--sym aliases)))
(helpful--insert-section-break)
@@ -2047,13 +2047,12 @@ state of the current symbol."
(insert " "))
(insert (helpful--make-forget-button helpful--sym helpful--callable-p))))
- (let ((aliases (helpful--aliases helpful--sym helpful--callable-p)))
- (when aliases
- (helpful--insert-section-break)
- (insert
- (helpful--heading "Aliases")
- (s-join "\n" (--map (helpful--format-alias it helpful--callable-p)
- aliases)))))
+ (when aliases
+ (helpful--insert-section-break)
+ (insert
+ (helpful--heading "Aliases")
+ (s-join "\n" (--map (helpful--format-alias it helpful--callable-p)
+ aliases))))
(helpful--insert-section-break)
diff --git a/test/helpful-unit-test.el b/test/helpful-unit-test.el
index bf5a2f1..95c3e3c 100644
--- a/test/helpful-unit-test.el
+++ b/test/helpful-unit-test.el
@@ -612,7 +612,7 @@ in."
(global-set-key (kbd "C-c M-S-d") #'helpful--dummy-command-alias)
(unwind-protect
- (let* ((keymaps (helpful--keymaps-containing-aliases #'helpful--dummy-command))
+ (let* ((keymaps (helpful--keymaps-containing-aliases #'helpful--dummy-command (helpful--aliases 'helpful--dummy-command t)))
(global-keybindings (cdr (assoc "global-map" keymaps))))
(should
(equal global-keybindings (list "C-c M-S-c" "C-c M-S-d"))))