emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/swiper 11444e8 1/2: Fix pathological swiper-isearch-bac


From: Basil L. Contovounesios
Subject: [elpa] externals/swiper 11444e8 1/2: Fix pathological swiper-isearch-backward
Date: Sun, 9 May 2021 11:38:07 -0400 (EDT)

branch: externals/swiper
commit 11444e82ad3ec4b718b03ee51fc3ba62cbba81bc
Author: Basil L. Contovounesios <contovob@tcd.ie>
Commit: Basil L. Contovounesios <contovob@tcd.ie>

    Fix pathological swiper-isearch-backward
    
    * swiper.el (swiper--isearch-next-item): When searching backward,
    test regexp without allocating a string for each candidate, which
    crawls to a stop in large buffers.
    
    Re: #2865.
    Fixes #2864.
---
 swiper.el | 32 ++++++++++++++------------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/swiper.el b/swiper.el
index d57d2bc..7e4f7ed 100644
--- a/swiper.el
+++ b/swiper.el
@@ -1398,24 +1398,20 @@ See `ivy-format-functions-alist' for further 
information."
         (nreverse cands)))))
 
 (defun swiper--isearch-next-item (re cands)
-  (if swiper--isearch-backward
-      (or
-       (cl-position-if
-        (lambda (x)
-          (and
-           (< x swiper--isearch-start-point)
-           (eq 0 (string-match-p
-                  re
-                  (buffer-substring-no-properties
-                   x swiper--isearch-start-point)))))
-        cands
-        :from-end t)
-       0)
-    (or
-     (cl-position-if
-      (lambda (x) (> x swiper--isearch-start-point))
-      cands)
-     0)))
+  (or (if swiper--isearch-backward
+          (save-excursion
+            ;; Match RE starting at each position in CANDS.
+            (setq re (concat "\\=\\(?:" re "\\)"))
+            (cl-position-if
+             (lambda (x)
+               (when (< x swiper--isearch-start-point)
+                 (goto-char x)
+                 ;; Note: Not quite the same as `looking-at' + `match-end'.
+                 (re-search-forward re swiper--isearch-start-point t)))
+             cands
+             :from-end t))
+        (cl-position swiper--isearch-start-point cands :test #'<))
+      0))
 
 (defun swiper--isearch-filter-ignore-order (re-full cands)
   (let (filtered-cands)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]