From 1ad6bd254bc9227b7161de598ca26a0e020dbe1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20Antol=C3=ADn?= Date: Wed, 15 Apr 2020 01:02:21 -0500 Subject: Only copy and highlight once the candidate is known to match Benchmarking suggests this is often close to twice as fast. --- orderless.el | 30 +++++++++++++++++------------- 1 file 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))))) -- cgit v1.0