[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/flx 50ff90fa08 017/182: add ido cache of narrowed list opt
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/flx 50ff90fa08 017/182: add ido cache of narrowed list optimization |
Date: |
Tue, 13 Dec 2022 03:59:15 -0500 (EST) |
branch: elpa/flx
commit 50ff90fa08a415c0ac121e105911a11eabb55edb
Author: Le Wang <le.wang@agworld.com.au>
Commit: Le Wang <le.wang@agworld.com.au>
add ido cache of narrowed list optimization
---
flx-ido.el | 50 ++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 40 insertions(+), 10 deletions(-)
diff --git a/flx-ido.el b/flx-ido.el
index 8fc647d611..9217da773c 100644
--- a/flx-ido.el
+++ b/flx-ido.el
@@ -8,24 +8,54 @@
;;; dynamically bound by ido
(defvar hist)
+(defvar flx-ido-narrowed-matches-hash (make-hash-table :test 'equal))
+
+(defun flx-ido-narrowed (query)
+ "Get the value from `flx-ido-narrowed-matches-hash' with the
+ longest prefix match."
+ (let (best-match)
+ (loop for key being the hash-key of flx-ido-narrowed-matches-hash
+ do (when (and (>= (length query) (length key))
+ (eq t
+ (compare-strings query 0 nil
+ key 0 nil))
+ (> (length key) (length best-match)))
+ (setq best-match key)
+ (when (= (length key)
+ (length query))
+ (return))))
+ (and best-match
+ (gethash best-match flx-ido-narrowed-matches-hash))))
+
(defun flx-ido-match (query items)
"Better sorting for flx ido matching."
(if (zerop (length query))
items
- (let ((cache flx-file-cache)
- matches)
- (mapc (lambda (item)
- (let ((score (flx-score item query cache)))
- (when score
- (push (cons item (car score)) matches))))
- items)
- (mapcar 'car (if ido-rotate
- matches
- (sort matches (lambda (x y) (> (cdr x) (cdr y)))))))))
+ (let ((existing (gethash query flx-ido-narrowed-matches-hash)))
+ (or existing
+ (let* ((narrowed-items (or (flx-ido-narrowed query)
+ items))
+ (matches (loop for item in narrowed-items
+ for score = (flx-score item query
flx-file-cache)
+ if score
+ collect (cons item (car score)) into matches
+ finally return matches))
+ res)
+ (setq res (mapcar
+ 'car
+ (if ido-rotate
+ matches
+ (sort matches
+ (lambda (x y) (> (cdr x) (cdr y)))))))
+ (puthash query res flx-ido-narrowed-matches-hash))))))
(defvar flx-ido-use t
"*Use flx matching for ido.")
+(defadvice ido-read-internal (before flx-ido-reset-hash activate)
+ "clear our narrowed hash."
+ (clrhash flx-ido-narrowed-matches-hash))
+
(defadvice ido-set-matches-1 (around flx-ido-set-matches-1 activate)
"Choose between the regular ido-set-matches-1 and my-ido-fuzzy-match"
(if flx-ido-use
- [nongnu] elpa/flx 26a1225431 137/182: rename optimization test, (continued)
- [nongnu] elpa/flx 26a1225431 137/182: rename optimization test, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 7a2601481c 142/182: Simplify flx-propertize, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx b95294518c 155/182: Debian and Ubuntu installation instructions, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 46040d0b09 160/182: Merge pull request #97 from antmak/patch-1, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 05600ff855 167/182: Merge pull request #103 from phst/add-license-file, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx e3b3f0533e 174/182: Merge pull request #108 from tarsiiformes/cleanup, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 48e10bf54f 177/182: Update to latest version of GPLv3 boilerplate, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 8ee8a877ab 028/182: boost entire match score, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 78dc69a666 023/182: fix query with CAPITAL letters, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 095f2e70f9 040/182: remove text property of selected item, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 50ff90fa08 017/182: add ido cache of narrowed list optimization,
ELPA Syncer <=
- [nongnu] elpa/flx 3208d8131e 043/182: make undecorate select item more thorough, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx fb1ded43df 044/182: cache cons cell lists too, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx d21ac098df 050/182: add option `flx-ido-use-faces', ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx f9bd16221b 063/182: update large collection guidelines, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 27bc47899a 075/182: Merge pull request #37 from artagnon/make, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx abe1a77c02 081/182: Merge pull request #38 from artagnon/cl-lib, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 9200e27309 083/182: use "flex" filtering when collection too large, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx c85273a6e8 009/182: fix helm demo typo, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx 7110df04e2 005/182: update tests, ELPA Syncer, 2022/12/13
- [nongnu] elpa/flx fabca711e9 013/182: fix typo, ELPA Syncer, 2022/12/13