emacs-diffs
[Top][All Lists]
Advanced

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

emacs-28 5978283: (xref--collect-matches-1): Remove some intermediate al


From: Dmitry Gutov
Subject: emacs-28 5978283: (xref--collect-matches-1): Remove some intermediate allocations
Date: Fri, 8 Oct 2021 11:46:42 -0400 (EDT)

branch: emacs-28
commit 59782839cb9ca7f3bc37bf00773db9ddc4cde61b
Author: Dmitry Gutov <dgutov@yandex.ru>
Commit: Dmitry Gutov <dgutov@yandex.ru>

    (xref--collect-matches-1): Remove some intermediate allocations
    
    * lisp/progmodes/xref.el: (xref--collect-matches-1):
    Rewrite to remove some intermediate allocations.
    Modest performance improvement.
---
 lisp/progmodes/xref.el | 54 ++++++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 26 deletions(-)

diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index d6e20c5..980ef4c 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1878,34 +1878,36 @@ Such as the current syntax table and the applied syntax 
properties."
                                  syntax-needed)))))
 
 (defun xref--collect-matches-1 (regexp file line line-beg line-end 
syntax-needed)
-  (let (match-pairs matches)
+  (let (matches
+        stop beg end
+        last-beg last-end
+        summary-end)
     (when syntax-needed
       (syntax-propertize line-end))
-    (while (and
-            ;; REGEXP might match an empty string.  Or line.
-            (or (null match-pairs)
-                (> (point) line-beg))
-            (re-search-forward regexp line-end t))
-      (push (cons (match-beginning 0)
-                  (match-end 0))
-            match-pairs))
-    (setq match-pairs (nreverse match-pairs))
-    (while match-pairs
-      (let* ((beg-end (pop match-pairs))
-             (beg-column (- (car beg-end) line-beg))
-             (end-column (- (cdr beg-end) line-beg))
-             (loc (xref-make-file-location file line beg-column))
-             (summary (buffer-substring (if matches (car beg-end) line-beg)
-                                        (if match-pairs
-                                            (caar match-pairs)
-                                          line-end))))
-        (when matches
-          (cl-decf beg-column (- (car beg-end) line-beg))
-          (cl-decf end-column (- (car beg-end) line-beg)))
-        (add-face-text-property beg-column end-column 'xref-match
-                                t summary)
-        (push (xref-make-match summary loc (- end-column beg-column))
-              matches)))
+    (while (not stop)
+      (if (and
+           ;; REGEXP might match an empty string.  Or line.
+           (not (and last-beg (eql end line-beg)))
+           (re-search-forward regexp line-end t))
+          (setq beg (match-beginning 0)
+                end (match-end 0)
+                summary-end beg)
+        (setq stop t
+              summary-end line-end))
+      (when last-beg
+        (let* ((beg-column (- last-beg line-beg))
+               (end-column (- last-end line-beg))
+               (summary-start (if matches last-beg line-beg))
+               (summary (buffer-substring summary-start
+                                          summary-end))
+               (loc (xref-make-file-location file line beg-column)))
+          (add-face-text-property (- last-beg summary-start)
+                                  (- last-end summary-start)
+                                  'xref-match t summary)
+          (push (xref-make-match summary loc (- end-column beg-column))
+                matches)))
+      (setq last-beg beg
+            last-end end))
     (nreverse matches)))
 
 (defun xref--find-file-buffer (file)



reply via email to

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