[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket m
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket matching |
Date: |
Sat, 7 Aug 2021 09:25:16 -0400 (EDT) |
branch: elpa/rust-mode
commit 99b128c6d0e7dc8af6ae3430364f3c92d2686009
Author: Micah Chalmer <micah@micahchalmer.net>
Commit: Micah Chalmer <micah@micahchalmer.net>
Fix slowness in angle bracket matching
The problem was caused by the logic that made it refontify the whole
buffer when "font-lock-syntactically-fontified" was set to a position
before the start of the region to be potentially fontified.
Unfortunately that variable is not reliably set when fontifying a large
buffer. Fortunately, the new logic is much simpler, and font-lock
already takes care of ensuring that everything before font-lock-beg was
syntactically fontified.
The other problem was calling syntax-ppss on positions known not to be
fontified yet.
This fixes both of these issues, and the angle bracket matching now
works on larger buffers without pausing on every keystroke.
---
rust-mode.el | 196 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 99 insertions(+), 97 deletions(-)
diff --git a/rust-mode.el b/rust-mode.el
index e451dfa..9e20aa2 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -428,24 +428,18 @@
part of it. Adjusts to include the r[#] of a raw string as
well."
- (let ((orig-beg font-lock-beg)
- (orig-end font-lock-end))
- (cond
- ;; If we are not syntactically fontified yet, we cannot correctly cover
- ;; anything less than the full buffer. The syntactic fontification
- ;; modifies the syntax, so until it's done we can't use the syntax to
- ;; determine what to fontify.
- ((< (or font-lock-syntactically-fontified 0) font-lock-end)
- (setq font-lock-beg 1)
- (setq font-lock-end (buffer-end 1)))
-
- ((let* ((beg-ppss (syntax-ppss font-lock-beg))
- (beg-in-cmnt (and (nth 4 beg-ppss) (nth 8 beg-ppss)))
- (beg-in-str (nth 3 beg-ppss))
- (end-ppss (syntax-ppss font-lock-end))
- (end-in-str (nth 3 end-ppss)))
-
- (when (and beg-in-str (> font-lock-beg (nth 8 beg-ppss)))
+ (save-excursion
+ (let ((orig-beg font-lock-beg)
+ (orig-end font-lock-end))
+
+ (let*
+ ;; It's safe to call `syntax-ppss' here on positions that are
+ ;; already syntactically fontified
+ ((beg-ppss (syntax-ppss font-lock-beg))
+ (beg-in-cmnt (and beg-ppss (nth 4 beg-ppss) (nth 8 beg-ppss)))
+ (beg-in-str (and beg-ppss (nth 3 beg-ppss) (nth 8 beg-ppss))))
+
+ (when (and beg-in-str (>= font-lock-beg beg-in-str))
(setq font-lock-beg (nth 8 beg-ppss))
(while (equal ?# (char-before font-lock-beg))
(setq font-lock-beg (1- font-lock-beg)))
@@ -453,18 +447,24 @@
(setq font-lock-beg (1- font-lock-beg))))
(when (and beg-in-cmnt (> font-lock-beg beg-in-cmnt))
- (setq font-lock-beg beg-in-cmnt))
-
- (when end-in-str
- (save-excursion
- (goto-char (nth 8 end-ppss))
- (ignore-errors (forward-sexp))
- (setq font-lock-end (max font-lock-end (point)))))
- )))
-
- (or (/= font-lock-beg orig-beg)
- (/= font-lock-end orig-end))
- ))
+ (setq font-lock-beg beg-in-cmnt)))
+
+ ;; We need to make sure that if the region ends inside a raw string, we
+ ;; extend it out past the end of it. But we can't use `syntax-ppss' to
+ ;; detect that, becaue that depends on font-lock already being done, and
we
+ ;; are trying to figure out how much to font-lock before that. So we use
+ ;; the regexp directly.
+ (save-match-data
+ (goto-char font-lock-beg)
+ (while (and (< (point) font-lock-end)
+ (re-search-forward rust-re-non-standard-string (buffer-end
1) t)
+ (<= (match-beginning 0) font-lock-end))
+ (setq font-lock-end (max font-lock-end (match-end 0)))
+ (goto-char (1+ (match-beginning 0)))))
+
+ (or (/= font-lock-beg orig-beg)
+ (/= font-lock-end orig-end))
+ )))
(defun rust-conditional-re-search-forward (regexp bound condition)
;; Search forward for regexp (with bound). If found, call condition and
return the found
@@ -492,77 +492,79 @@
(set-match-data (nth 1 ret-list))
(nth 0 ret-list))))
+(defconst rust-re-non-standard-string
+ (rx
+ (or
+ ;; Raw string: if it matches, it ends up with the starting character
+ ;; of the string as group 1, any ending backslashes as group 4, and
+ ;; the ending character as either group 5 or group 6.
+ (seq
+ ;; The "r" starts the raw string. Capture it as group 1 to mark it as
such syntactically:
+ (group "r")
+
+ ;; Then either:
+ (or
+ ;; a sequence at least one "#" (followed by quote). Capture all
+ ;; but the last "#" as group 2 for this case.
+ (seq (group (* "#")) "#\"")
+
+ ;; ...or a quote without any "#". Capture it as group 3. This is
+ ;; used later to match the opposite quote only if this capture
+ ;; occurred
+ (group "\""))
+
+ ;; The contents of the string:
+ (*? anything)
+
+ ;; If there are any backslashes at the end of the string, capture
+ ;; them as group 4 so we can suppress the normal escape syntax
+ ;; parsing:
+ (group (* "\\"))
+
+ ;; Then the end of the string--the backreferences ensure that we
+ ;; only match the kind of ending that corresponds to the beginning
+ ;; we had:
+ (or
+ ;; There were "#"s - capture the last one as group 5 to mark it as
+ ;; the end of the string:
+ (seq "\"" (backref 2) (group "#"))
+
+ ;; No "#"s - capture the ending quote (using a backref to group 3,
+ ;; so that we can't match a quote if we had "#"s) as group 6
+ (group (backref 3))))
+
+ ;; Character literal: match the beginning ' of a character literal
+ ;; as group 7, and the ending one as group 8
+ (seq
+ (group "'")
+ (or
+ (seq
+ "\\"
+ (or
+ (: "U" (= 8 xdigit))
+ (: "u" (= 4 xdigit))
+ (: "x" (= 2 xdigit))
+ (any "'nrt0\"\\")))
+ (not (any "'\\"))
+ )
+ (group "'"))
+ )
+ ))
+
(defun rust-look-for-non-standard-string (bound)
;; Find a raw string or character literal, but only if it's not in the middle
;; of another string or a comment.
- (let* ((non-standard-str-regexp
- (rx
- (or
- ;; Raw string: if it matches, it ends up with the starting
character
- ;; of the string as group 1, any ending backslashes as group 4, and
- ;; the ending character as either group 5 or group 6.
- (seq
- ;; The "r" starts the raw string. Capture it as group 1 to mark
it as such syntactically:
- (group "r")
-
- ;; Then either:
- (or
- ;; a sequence at least one "#" (followed by quote). Capture all
- ;; but the last "#" as group 2 for this case.
- (seq (group (* "#")) "#\"")
-
- ;; ...or a quote without any "#". Capture it as group 3. This is
- ;; used later to match the opposite quote only if this capture
- ;; occurred
- (group "\""))
-
- ;; The contents of the string:
- (*? anything)
-
- ;; If there are any backslashes at the end of the string, capture
- ;; them as group 4 so we can suppress the normal escape syntax
- ;; parsing:
- (group (* "\\"))
-
- ;; Then the end of the string--the backreferences ensure that we
- ;; only match the kind of ending that corresponds to the beginning
- ;; we had:
- (or
- ;; There were "#"s - capture the last one as group 5 to mark it
as
- ;; the end of the string:
- (seq "\"" (backref 2) (group "#"))
-
- ;; No "#"s - capture the ending quote (using a backref to group
3,
- ;; so that we can't match a quote if we had "#"s) as group 6
- (group (backref 3))))
-
- ;; Character literal: match the beginning ' of a character literal
- ;; as group 7, and the ending one as group 8
- (seq
- (group "'")
- (or
- (seq
- "\\"
- (or
- (: "U" (= 8 xdigit))
- (: "u" (= 4 xdigit))
- (: "x" (= 2 xdigit))
- (any "'nrt0\"\\")))
- (not (any "'\\"))
- )
- (group "'"))
- )
- )))
- (rust-conditional-re-search-forward
- non-standard-str-regexp bound
- (lambda ()
- (let ((pstate (syntax-ppss (match-beginning 0))))
- (not
- (or
- (nth 4 pstate) ;; Skip if in a comment
- (and (nth 3 pstate) (wholenump (nth 8 pstate)) (< (nth 8 pstate)
(match-beginning 0))) ;; Skip if in a string that isn't starting here
- )))))))
+ (rust-conditional-re-search-forward
+ rust-re-non-standard-string
+ bound
+ (lambda ()
+ (let ((pstate (syntax-ppss (match-beginning 0))))
+ (not
+ (or
+ (nth 4 pstate) ;; Skip if in a comment
+ (and (nth 3 pstate) (wholenump (nth 8 pstate)) (< (nth 8 pstate)
(match-beginning 0))) ;; Skip if in a string that isn't starting here
+ ))))))
(defun rust-syntax-class-before-point ()
(when (> (point) 1)
- [nongnu] elpa/rust-mode 13c7e25 105/486: Ignore byte-compiled files, (continued)
- [nongnu] elpa/rust-mode 13c7e25 105/486: Ignore byte-compiled files, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3878cc6 107/486: Allow user to override which emacs is used in run_rust_emacs_tests.sh, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6b57bbf 117/486: Make features (and their tests) work on emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4d633fc 125/486: Merge pull request #32 from MicahChalmer/raw-string-handling, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8d99bf8 126/486: Merge pull request #31 from pnkfelix/more-robust-test-driver, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e16c37c 161/486: Remove Marmalade from the README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee171df 172/486: test $EMACS directly rather than using "which", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d1ed015 173/486: Distinguish face for doc-comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode c9c7871 179/486: Merge pull request #79 from MicahChalmer/angle-bracket-madness, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee564d5 185/486: Merge pull request #85 from talchas/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket matching,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 5e77aed 191/486: Correcting highlighting of capitals in function names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e51aaa 194/486: Merge pull request #69 from tromey/safe-local-variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 012537b 195/486: remove byte-compiler warnings and prevent future ones, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 866df37 196/486: make rust-mode use lexical binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6252cf1 217/486: Fix indentation of closing delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectly highlighted as modules., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86d636a 223/486: Remove duplicate keywords, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b1cca0f 222/486: Merge pull request #72 from birkenfeld/builtin-face, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 061e6d8 214/486: Merge pull request #109 from mrBliss/highlight-unsafe, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86c55b1 220/486: Integrate rustfmt support, ELPA Syncer, 2021/08/07