aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitry Gutov2021-10-08 18:25:55 +0300
committerDmitry Gutov2021-10-08 18:44:54 +0300
commit59782839cb9ca7f3bc37bf00773db9ddc4cde61b (patch)
tree955ffe67b1ec2aa642d6bf2f764b4045499ee867
parent1c7d056f4d38d212b23353f0d98d288bfa74f755 (diff)
downloademacs-59782839cb9ca7f3bc37bf00773db9ddc4cde61b.tar.gz
emacs-59782839cb9ca7f3bc37bf00773db9ddc4cde61b.zip
(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.
-rw-r--r--lisp/progmodes/xref.el54
1 files changed, 28 insertions, 26 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index d6e20c54166..980ef4c8d5d 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."
1878 syntax-needed))))) 1878 syntax-needed)))))
1879 1879
1880(defun xref--collect-matches-1 (regexp file line line-beg line-end syntax-needed) 1880(defun xref--collect-matches-1 (regexp file line line-beg line-end syntax-needed)
1881 (let (match-pairs matches) 1881 (let (matches
1882 stop beg end
1883 last-beg last-end
1884 summary-end)
1882 (when syntax-needed 1885 (when syntax-needed
1883 (syntax-propertize line-end)) 1886 (syntax-propertize line-end))
1884 (while (and 1887 (while (not stop)
1885 ;; REGEXP might match an empty string. Or line. 1888 (if (and
1886 (or (null match-pairs) 1889 ;; REGEXP might match an empty string. Or line.
1887 (> (point) line-beg)) 1890 (not (and last-beg (eql end line-beg)))
1888 (re-search-forward regexp line-end t)) 1891 (re-search-forward regexp line-end t))
1889 (push (cons (match-beginning 0) 1892 (setq beg (match-beginning 0)
1890 (match-end 0)) 1893 end (match-end 0)
1891 match-pairs)) 1894 summary-end beg)
1892 (setq match-pairs (nreverse match-pairs)) 1895 (setq stop t
1893 (while match-pairs 1896 summary-end line-end))
1894 (let* ((beg-end (pop match-pairs)) 1897 (when last-beg
1895 (beg-column (- (car beg-end) line-beg)) 1898 (let* ((beg-column (- last-beg line-beg))
1896 (end-column (- (cdr beg-end) line-beg)) 1899 (end-column (- last-end line-beg))
1897 (loc (xref-make-file-location file line beg-column)) 1900 (summary-start (if matches last-beg line-beg))
1898 (summary (buffer-substring (if matches (car beg-end) line-beg) 1901 (summary (buffer-substring summary-start
1899 (if match-pairs 1902 summary-end))
1900 (caar match-pairs) 1903 (loc (xref-make-file-location file line beg-column)))
1901 line-end)))) 1904 (add-face-text-property (- last-beg summary-start)
1902 (when matches 1905 (- last-end summary-start)
1903 (cl-decf beg-column (- (car beg-end) line-beg)) 1906 'xref-match t summary)
1904 (cl-decf end-column (- (car beg-end) line-beg))) 1907 (push (xref-make-match summary loc (- end-column beg-column))
1905 (add-face-text-property beg-column end-column 'xref-match 1908 matches)))
1906 t summary) 1909 (setq last-beg beg
1907 (push (xref-make-match summary loc (- end-column beg-column)) 1910 last-end end))
1908 matches)))
1909 (nreverse matches))) 1911 (nreverse matches)))
1910 1912
1911(defun xref--find-file-buffer (file) 1913(defun xref--find-file-buffer (file)