branch: master
commit 9f21e1d5258382f6426b5a08cea5971a8e955ad4
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Add a matching optimization
* ivy.el (ivy-completions): When the new regex `re' is a contains the
old regex `ivy--old-re', it must be true that all candidates that
match `re' are contained inside all candidates that match
`ivy--old-re', i.e. the pre-computed in the last step
`ivy--old-cands'.
This should speed up completion for large (~100k) amount of candidates,
for the particular case of regex simply being extended.
---
ivy.el | 20 +++++++++++++-------
1 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/ivy.el b/ivy.el
index bd43883..ebbb186 100644
--- a/ivy.el
+++ b/ivy.el
@@ -550,13 +550,19 @@ NAME is a string of words separated by spaces that is
used to
build a regex.
CANDIDATES is a list of strings."
(let* ((re (ivy--regex name))
- (cands (if (and (equal re ivy--old-re)
- ivy--old-cands)
- ivy--old-cands
- (ignore-errors
- (cl-remove-if-not
- (lambda (x) (string-match re x))
- candidates))))
+ (cands (cond ((and (equal re ivy--old-re)
+ ivy--old-cands)
+ ivy--old-cands)
+ ((and ivy--old-re (eq 0 (cl-search ivy--old-re re)))
+ (ignore-errors
+ (cl-remove-if-not
+ (lambda (x) (string-match re x))
+ ivy--old-cands)))
+ (t
+ (ignore-errors
+ (cl-remove-if-not
+ (lambda (x) (string-match re x))
+ candidates)))))
(tail (nthcdr ivy--index ivy--old-cands))
(ww (window-width))
idx)