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

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

[nongnu] elpa/flx bebf045684 062/182: gracefully handle large collection


From: ELPA Syncer
Subject: [nongnu] elpa/flx bebf045684 062/182: gracefully handle large collections
Date: Tue, 13 Dec 2022 03:59:29 -0500 (EST)

branch: elpa/flx
commit bebf04568461f0af4311033663fbd21ca7a3ad5e
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>

    gracefully handle large collections
    
    fixes #24
---
 flx-ido.el | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)

diff --git a/flx-ido.el b/flx-ido.el
index e73ae64449..cc7edb4153 100644
--- a/flx-ido.el
+++ b/flx-ido.el
@@ -57,6 +57,10 @@
 (require 'ido)
 (require 'flx)
 
+(defcustom flx-ido-threshhold 6000
+  "flx will not kick in until collection is filtered below this size with 
\"flex\"."
+  :group 'ido)
+
 
 (defcustom flx-ido-use-faces t
   "Use `flx-highlight-face' to indicate characters contributing to best score."
@@ -135,16 +139,23 @@ item, in which case, the ending items are deleted."
       (mapcar 'car things))))
 
 (defun flx-ido-match-internal (query items)
-  (let* ((matches (loop for item in items
-                        for string = (if (consp item) (car item) item)
-                        for score = (flx-score string query flx-file-cache)
-                        if score
-                        collect (cons item score)
-                        into matches
-                        finally return matches)))
-    (flx-ido-decorate (ido-delete-runs
-                       (sort matches
-                             (lambda (x y) (> (cadr x) (cadr y))))))))
+  (if (< (length items) flx-ido-threshhold)
+      (let* ((matches (loop for item in items
+                            for string = (if (consp item) (car item) item)
+                            for score = (flx-score string query flx-file-cache)
+                            if score
+                            collect (cons item score)
+                            into matches
+                            finally return matches)))
+        (flx-ido-decorate (ido-delete-runs
+                           (sort matches
+                                 (lambda (x y) (> (cadr x) (cadr y)))))))
+    (let ((regexp (mapconcat 'identity (split-string query "" t) ".*")))
+      (loop for item in items
+            if (string-match regexp (if (consp item) (car item) item))
+            collect item
+            into matches
+            finally return matches))))
 
 (defun flx-ido-key-for-query (query)
   (concat ido-current-directory query))



reply via email to

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