branch: elpa/isl
commit 669ef181f4244b7637aea24d596a0d2389c4304a
Author: Thierry Volpiatto <[email protected]>
Commit: Thierry Volpiatto <[email protected]>
Avoid one loop in isl-update when computing closest overlay
---
isl.el | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/isl.el b/isl.el
index c907d76a59e..8d416293895 100644
--- a/isl.el
+++ b/isl.el
@@ -994,9 +994,8 @@ See `isl-requires-pattern'."
(listp buffer-invisibility-spec))
(mapc 'remove-from-invisibility-spec buffer-invisibility-spec))
(let ((count 1)
- ov
- bounds
- go)
+ (npos (point-max)) ; nearest match position from start.
+ ov bounds go ovs-alist)
(unless (string= isl-pattern "")
(save-excursion
(goto-char (point-min))
@@ -1018,6 +1017,12 @@ See `isl-requires-pattern'."
(overlay-put ov 'isl t)
(overlay-put ov 'pos count)
(overlay-put ov 'face 'isl-match)
+ (let* ((pos (or isl-initial-pos 0))
+ (ovpos (car bounds))
+ (diff (if (> pos ovpos)
+ (- pos ovpos) (- ovpos pos))))
+ (push (cons diff ov) ovs-alist)
+ (setq npos (min diff npos)))
(when isl-multi-search-in-line
(isl--highlight-items-in-line (car bounds) (cdr bounds)))
(cl-incf count))
@@ -1035,9 +1040,7 @@ See `isl-requires-pattern'."
(if (null isl--item-overlays)
(progn (setq isl--number-results 0)
(and isl-initial-pos (goto-char isl-initial-pos)))
- (setq isl--last-overlay
- (isl-closest-overlay
- (or isl-initial-pos 0) isl--item-overlays)
+ (setq isl--last-overlay (cdr (assq npos ovs-alist))
isl--number-results (max (length isl--item-overlays) 0))
(isl--highlight-last-overlay 'isl-on)
(isl-make-iterator)