diff options
| author | Omar Antolín <omar.antolin@gmail.com> | 2020-04-15 01:02:21 -0500 |
|---|---|---|
| committer | Omar Antolín <omar.antolin@gmail.com> | 2020-04-15 01:02:21 -0500 |
| commit | 1ad6bd254bc9227b7161de598ca26a0e020dbe1e (patch) | |
| tree | 8efef066c10fb952c1c12e2113d711bd2e065b0c | |
| parent | ac12bc4d54ea5ba9f909aaf3c2534b2968dcc745 (diff) | |
Only copy and highlight once the candidate is known to match
Benchmarking suggests this is often close to twice as fast.
| -rw-r--r-- | orderless.el | 30 |
1 files changed, 17 insertions, 13 deletions
diff --git a/orderless.el b/orderless.el index 08a2f41..c7b6e1c 100644 --- a/orderless.el +++ b/orderless.el @@ -45,14 +45,14 @@ ;;; Code: -(defun orderless-highlight-match (regexp string) - (when (string-match regexp string) - (font-lock-prepend-text-property - (match-beginning 0) - (match-end 0) - 'face 'completions-common-part - string) - t)) +(defun orderless--highlight-match (regexp string) + ;; only call this when the match has already been checked! + (string-match regexp string) + (font-lock-prepend-text-property + (match-beginning 0) + (match-end 0) + 'face 'completions-common-part + string)) (defun orderless-all-completions (string table pred _point) (save-match-data @@ -66,11 +66,15 @@ (progn (setq all (cl-loop for original in all - for candidate = (copy-sequence original) - when (cl-loop for regexp in regexps - always (orderless-highlight-match - regexp candidate)) - collect candidate)) + when + (cl-loop for regexp in regexps + always (string-match-p regexp original)) + collect ; it's a match, copy and highlight + (cl-loop with candidate = (copy-sequence original) + for regexp in regexps do + (orderless--highlight-match + regexp candidate) + finally (return candidate)))) (when all (nconc all (length prefix)))) (invalid-regexp nil))))) |
