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

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

[elpa] scratch/mheerdegen-preview 54e3b67 16/32: WIP: Optimize caching


From: Michael Heerdegen
Subject: [elpa] scratch/mheerdegen-preview 54e3b67 16/32: WIP: Optimize caching
Date: Sat, 20 Oct 2018 18:19:00 -0400 (EDT)

branch: scratch/mheerdegen-preview
commit 54e3b67ffa0e6e2752971a70d856daabbdacb5a3
Author: Michael Heerdegen <address@hidden>
Commit: Michael Heerdegen <address@hidden>

    WIP: Optimize caching
---
 packages/el-search/el-search.el | 48 +++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/packages/el-search/el-search.el b/packages/el-search/el-search.el
index 35ef3b5..4715149 100644
--- a/packages/el-search/el-search.el
+++ b/packages/el-search/el-search.el
@@ -1662,8 +1662,8 @@ PATTERN and combining the heuristic matchers of the 
subpatterns."
       (walker tree)
       elements)))
 
-(defun el-search-heuristic-buffer-matcher (pattern)
-  (let ((heuristic-matcher (el-search-heuristic-matcher pattern)))
+(defun el-search-heuristic-buffer-matcher (pattern &optional hm)
+  (let ((heuristic-matcher (or hm (el-search-heuristic-matcher pattern))))
     (lambda (file-name-or-buffer)
       (el-search--message-no-log "%s"
                                  (if (stringp file-name-or-buffer)
@@ -1803,7 +1803,7 @@ With ALLOW-LEADING-WHITESPACE non-nil, the match may
 be preceded by whitespace."
   (el-search--looking-at-1 (el-search-make-matcher pattern) 
allow-leading-whitespace))
 
-(defun el-search--all-matches (search)
+(defun el-search--all-matches (search &optional dont-copy)
   "Return a stream of all matches of SEARCH.
 The returned stream will always start searching from the
 beginning anew even when SEARCH has been used interactively or
@@ -1817,7 +1817,7 @@ The elements of the returned stream will have the form
 where BUFFER or FILE is the buffer or file where a match has been
 found (exactly one of the two will be nil), and MATCH-BEG is the
 position of the beginning of the match."
-  (let* ((search (el-search-reset-search (copy-el-search-object search)))
+  (let* ((search (if dont-copy search (el-search-reset-search 
(copy-el-search-object search))))
          (head (el-search-object-head search)))
     (seq-filter
      #'identity ;we use `nil' as a "skip" tag
@@ -1862,7 +1862,9 @@ position of the beginning of the match."
   (setf (el-search-head-heuristic-matcher head)
         (el-search-heuristic-matcher pattern))
   (setf (el-search-head-heuristic-buffer-matcher head)
-        (el-search-heuristic-buffer-matcher pattern))
+        (el-search-heuristic-buffer-matcher
+         pattern
+         (el-search-head-heuristic-matcher head)))
   head)
 
 (defun el-search-compile-pattern-in-search (search)
@@ -2509,18 +2511,26 @@ created.")
                      (_
                       ;; (message "Refreshing match count data") (sit-for 1)
                       (redisplay) ;don't delay highlighting
-                      (setq-local el-search--buffer-match-count-data
-                                  (let ((stream-of-buffer-matches
-                                         (seq-map #'cadr
-                                                  (el-search--all-matches
-                                                   (el-search-make-search
-                                                    
(el-search--current-pattern)
-                                                    (let ((current-buffer 
(current-buffer)))
-                                                      (lambda () (stream (list 
current-buffer)))))))))
-                                    (list
-                                     el-search--current-search
-                                     (buffer-chars-modified-tick)
-                                     stream-of-buffer-matches)))
+                      (let ((new-search (el-search-make-search
+                                         (el-search--current-pattern)
+                                         (let ((current-buffer 
(current-buffer)))
+                                           (lambda () (stream (list 
current-buffer)))))))
+                        (let ((head (el-search-object-head new-search)))
+                          ;; reuse already existing heuristic matchers
+                          (setf (el-search-head-heuristic-matcher head)
+                                (el-search-head-heuristic-matcher
+                                 (el-search-object-head 
el-search--current-search)))
+                          (setf (el-search-head-heuristic-buffer-matcher head)
+                                (el-search-head-heuristic-buffer-matcher
+                                 (el-search-object-head 
el-search--current-search))))
+                        (setq-local el-search--buffer-match-count-data
+                                    (let ((stream-of-buffer-matches
+                                           (seq-map #'cadr
+                                                    (el-search--all-matches 
new-search 'dont-copy))))
+                                      (list
+                                       el-search--current-search
+                                       (buffer-chars-modified-tick)
+                                       stream-of-buffer-matches))))
                       (setq el-search--this-session-match-count-data
                             el-search--buffer-match-count-data)))
 
@@ -2799,8 +2809,8 @@ continued."
   (interactive "P")
   (el-search--set-this-command-refresh-message-maybe)
   (unless (eq last-command this-command)
-    (el-search--set-search-origin-maybe))
-  (el-search-compile-pattern-in-search el-search--current-search)
+    (el-search--set-search-origin-maybe)
+    (el-search-compile-pattern-in-search el-search--current-search))
   (el-search-protect-search-head
    (el-search-when-unwind
        (unwind-protect



reply via email to

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