branch: externals/orderless
commit 8cea82b6d395078d0105f4957d4a95206dc9c7ba
Merge: 75d3398056 9c1b276fe4
Author: Omar AntolĂn Camarena <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #97 from minad/optimize-try
Optimize orderless-try-completion
---
orderless.el | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/orderless.el b/orderless.el
index a458f329d5..9250756688 100644
--- a/orderless.el
+++ b/orderless.el
@@ -458,17 +458,24 @@ match, it completes to that match. If there are no
matches, it
returns nil. In any other case it \"completes\" STRING to
itself, without moving POINT.
This function is part of the `orderless' completion style."
- (let ((all (orderless-filter string table pred)))
- (cond
- ((null all) nil)
- ((null (cdr all))
- (if (equal string (car all))
- t ; unique exact match
- (let ((full (concat
- (car (orderless--prefix+pattern string table pred))
- (car all))))
- (cons full (length full)))))
- (t (cons string point)))))
+ (catch 'orderless--many
+ (let (one)
+ ;; Abuse all-completions/orderless-filter as a fast search loop.
+ ;; Should be more or less allocation-free since our "predicate"
+ ;; always returns nil.
+ (orderless-filter string table
+ (lambda (str)
+ (when (or (not pred) (funcall pred str))
+ (when one
+ (throw 'orderless--many (cons string point)))
+ (setq one str))
+ nil))
+ (when one
+ (if (equal string one)
+ t ;; unique exact match
+ (setq one (concat (car (orderless--prefix+pattern string table pred))
+ one))
+ (cons one (length one)))))))
;;;###autoload
(add-to-list 'completion-styles-alist