summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Gutov <dgutov@yandex.ru>2017-05-02 00:09:09 +0300
committerDmitry Gutov <dgutov@yandex.ru>2017-05-02 00:09:30 +0300
commitc99a3b90a010448c14475666cb78f05860b0e1c2 (patch)
tree683b307c094c5c777e2cb6a5666cab4292640beb
parent80407a2d3fa0827288eaf4006f2af5e011402631 (diff)
downloademacs-c99a3b90a010448c14475666cb78f05860b0e1c2.tar.gz
Speed up project-find-regexp for simple regexps
* lisp/progmodes/xref.el (xref--regexp-syntax-dependent-p): New function. (xref--collect-matches): Use it. Don't try to enable the appropriate major mode and file-local variables if the regexp does not depend on the buffer's syntax (bug#26710). (xref--collect-matches-1): Don't syntax-propertize in that case either.
-rw-r--r--lisp/progmodes/xref.el28
1 files changed, 22 insertions, 6 deletions
diff --git a/lisp/progmodes/xref.el b/lisp/progmodes/xref.el
index d0636ba6355..c9df450d5f2 100644
--- a/lisp/progmodes/xref.el
+++ b/lisp/progmodes/xref.el
@@ -1004,6 +1004,17 @@ directory, used as the root of the ignore globs."
(match-string 1 str)))))
str t t))
+(defun xref--regexp-syntax-dependent-p (str)
+ "Return non-nil when STR depends on the buffer's syntax.
+Such as the current syntax table and the applied syntax properties."
+ (let ((case-fold-search nil))
+ (string-match-p (rx
+ (or string-start (not (in ?\\)))
+ (0+ (= 2 ?\\))
+ ?\\
+ (in ?b ?B ?< ?> ?w ?W ?_ ?s ?S))
+ str)))
+
(defvar xref--last-visiting-buffer nil)
(defvar xref--temp-buffer-file-name nil)
@@ -1017,7 +1028,8 @@ directory, used as the root of the ignore globs."
(defun xref--collect-matches (hit regexp tmp-buffer)
(pcase-let* ((`(,line ,file ,text) hit)
- (buf (xref--find-buffer-visiting file)))
+ (buf (xref--find-buffer-visiting file))
+ (syntax-needed (xref--regexp-syntax-dependent-p regexp)))
(if buf
(with-current-buffer buf
(save-excursion
@@ -1025,12 +1037,14 @@ directory, used as the root of the ignore globs."
(forward-line (1- line))
(xref--collect-matches-1 regexp file line
(line-beginning-position)
- (line-end-position))))
+ (line-end-position)
+ syntax-needed)))
;; Using the temporary buffer is both a performance and a buffer
;; management optimization.
(with-current-buffer tmp-buffer
(erase-buffer)
- (unless (equal file xref--temp-buffer-file-name)
+ (when (and syntax-needed
+ (not (equal file xref--temp-buffer-file-name)))
(insert-file-contents file nil 0 200)
;; Can't (setq-local delay-mode-hooks t) because of
;; bug#23272, but the performance penalty seems minimal.
@@ -1046,11 +1060,13 @@ directory, used as the root of the ignore globs."
(goto-char (point-min))
(xref--collect-matches-1 regexp file line
(point)
- (point-max))))))
+ (point-max)
+ syntax-needed)))))
-(defun xref--collect-matches-1 (regexp file line line-beg line-end)
+(defun xref--collect-matches-1 (regexp file line line-beg line-end syntax-needed)
(let (matches)
- (syntax-propertize line-end)
+ (when syntax-needed
+ (syntax-propertize line-end))
;; FIXME: This results in several lines with the same
;; summary. Solve with composite pattern?
(while (and