[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/company 26e501d 2/3: Regain performance lost due to doi
From: |
ELPA Syncer |
Subject: |
[elpa] externals/company 26e501d 2/3: Regain performance lost due to doing the search twice |
Date: |
Thu, 13 May 2021 15:57:09 -0400 (EDT) |
branch: externals/company
commit 26e501d478f8336a3289468142208c9764d78644
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>
Regain performance lost due to doing the search twice
---
company.el | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)
diff --git a/company.el b/company.el
index 5dbc3c5..24ccbfe 100644
--- a/company.el
+++ b/company.el
@@ -1670,17 +1670,21 @@ Keywords and function definition names are ignored."
(save-excursion
(cl-delete-if
(lambda (candidate)
- (when (catch 'done
- (goto-char (1- start-point))
- (while (search-backward candidate w-start t)
- (when (save-match-data
- (company--occurrence-predicate))
- (throw 'done t)))
- (goto-char start-point)
- (while (search-forward candidate w-end t)
- (when (save-match-data
- (company--occurrence-predicate))
- (throw 'done t))))
+ (goto-char w-start)
+ (when (and (search-forward candidate w-end t)
+ ;; ^^^ optimize for large lists where most elements
+ ;; won't have a match.
+ (catch 'done
+ (goto-char (1- start-point))
+ (while (search-backward candidate w-start t)
+ (when (save-match-data
+ (company--occurrence-predicate))
+ (throw 'done t)))
+ (goto-char start-point)
+ (while (search-forward candidate w-end t)
+ (when (save-match-data
+ (company--occurrence-predicate))
+ (throw 'done t)))))
(push
(cons candidate
(funcall company-occurrence-weight-function