emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/orderless 1ad6bd254b 021/204: Only copy and highlight o


From: ELPA Syncer
Subject: [elpa] externals/orderless 1ad6bd254b 021/204: Only copy and highlight once the candidate is known to match
Date: Tue, 11 Jan 2022 12:58:14 -0500 (EST)

branch: externals/orderless
commit 1ad6bd254bc9227b7161de598ca26a0e020dbe1e
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    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 08a2f41cd3..c7b6e1c833 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)))))
 



reply via email to

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