Commit 0d5caa9a authored by Alan Mackenzie's avatar Alan Mackenzie

Optimize for typing characters into long C++ raw strings.

* lisp/progmodes/cc-fonts.el (c-font-lock-complex-decl-prepare)
(c-font-lock-objc-methods) (c-font-lock-declarations, c-font-lock-enum-tail)
(c-font-lock-cut-off-declarators, c-font-lock-enclosing-decls): If the chunk
been fontified consists entirely of comments and strings, don't attempt to
perform the function's action.

* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Don't
expand (c-new-BEG c-new-END) unnecessarily to the entire raw string being
fontified.
(c-fl-decl-start, c-fl-decl-end): When in a (raw or otherwise) string, don't
return a position outside of the string (which used to cause unneeded
fontification).
parent 085929ca
Pipeline #1419 passed with stage
in 52 minutes
This diff is collapsed.
...@@ -1192,8 +1192,6 @@ Note that the style variables are always made local to the buffer." ...@@ -1192,8 +1192,6 @@ Note that the style variables are always made local to the buffer."
(beg-literal-type (and beg-limits (beg-literal-type (and beg-limits
(c-literal-type beg-limits)))) (c-literal-type beg-limits))))
(when (eq end-literal-type 'string)
(setq c-new-END (max c-new-END (cdr end-limits))))
;; It is possible the buffer change will include inserting a string quote. ;; It is possible the buffer change will include inserting a string quote.
;; This could have the effect of flipping the meaning of any following ;; This could have the effect of flipping the meaning of any following
;; quotes up until the next unescaped EOL. Also guard against the change ;; quotes up until the next unescaped EOL. Also guard against the change
...@@ -1282,7 +1280,6 @@ Note that the style variables are always made local to the buffer." ...@@ -1282,7 +1280,6 @@ Note that the style variables are always made local to the buffer."
(when (and (eq beg-literal-type 'string) (when (and (eq beg-literal-type 'string)
(memq (char-after (car beg-limits)) c-string-delims)) (memq (char-after (car beg-limits)) c-string-delims))
(setq c-new-BEG (min c-new-BEG (car beg-limits)))
(c-clear-char-property (car beg-limits) 'syntax-table) (c-clear-char-property (car beg-limits) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (car beg-limits)))))) (c-truncate-semi-nonlit-pos-cache (car beg-limits))))))
...@@ -1832,6 +1829,9 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") ...@@ -1832,6 +1829,9 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
;; declaration is one which does not start outside of struct braces (and ;; declaration is one which does not start outside of struct braces (and
;; similar) enclosing POS. Brace list braces here are not "similar". ;; similar) enclosing POS. Brace list braces here are not "similar".
;; ;;
;; POS being in a literal does not count as being in a declaration (on
;; pragmatic grounds).
;;
;; This function is called indirectly from font locking stuff - either from ;; This function is called indirectly from font locking stuff - either from
;; c-after-change (to prepare for after-change font-locking) or from font ;; c-after-change (to prepare for after-change font-locking) or from font
;; lock context (etc.) fontification. ;; lock context (etc.) fontification.
...@@ -1842,92 +1842,92 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") ...@@ -1842,92 +1842,92 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
capture-opener capture-opener
bod-lim bo-decl) bod-lim bo-decl)
(goto-char (c-point 'bol new-pos)) (goto-char (c-point 'bol new-pos))
(when lit-start ; Comment or string. (unless lit-start
(goto-char lit-start)) (setq bod-lim (c-determine-limit 500))
(setq bod-lim (c-determine-limit 500))
;; In C++ Mode, first check if we are within a (possibly nested) lambda
;; In C++ Mode, first check if we are within a (possibly nested) lambda ;; form capture list.
;; form capture list. (when (c-major-mode-is 'c++-mode)
(when (c-major-mode-is 'c++-mode) (let ((paren-state (c-parse-state))
(let ((paren-state (c-parse-state)) opener)
opener) (save-excursion
(save-excursion (while (setq opener (c-pull-open-brace paren-state))
(while (setq opener (c-pull-open-brace paren-state)) (goto-char opener)
(goto-char opener) (if (c-looking-at-c++-lambda-capture-list)
(if (c-looking-at-c++-lambda-capture-list) (setq capture-opener (point)))))))
(setq capture-opener (point)))))))
(while
(while ;; Go to a less nested declaration each time round this loop.
;; Go to a less nested declaration each time round this loop. (and
(and (setq old-pos (point))
(setq old-pos (point)) (let (pseudo)
(let (pseudo) (while
(while (progn
(progn (c-syntactic-skip-backward "^;{}" bod-lim t)
(c-syntactic-skip-backward "^;{}" bod-lim t) (and (eq (char-before) ?})
(and (eq (char-before) ?}) (save-excursion
(save-excursion (backward-char)
(backward-char) (setq pseudo (c-cheap-inside-bracelist-p (c-parse-state))))))
(setq pseudo (c-cheap-inside-bracelist-p (c-parse-state)))))) (goto-char pseudo))
(goto-char pseudo)) t)
t) (> (point) bod-lim)
(> (point) bod-lim) (progn (c-forward-syntactic-ws)
(progn (c-forward-syntactic-ws) ;; Have we got stuck in a comment at EOB?
;; Have we got stuck in a comment at EOB? (not (and (eobp)
(not (and (eobp) (c-literal-start))))
(c-literal-start)))) (< (point) old-pos)
(< (point) old-pos) (progn (setq bo-decl (point))
(progn (setq bo-decl (point)) (or (not (looking-at c-protection-key))
(or (not (looking-at c-protection-key)) (c-forward-keyword-clause 1)))
(c-forward-keyword-clause 1))) (progn
(progn ;; Are we looking at a keyword such as "template" or
;; Are we looking at a keyword such as "template" or ;; "typedef" which can decorate a type, or the type itself?
;; "typedef" which can decorate a type, or the type itself? (when (or (looking-at c-prefix-spec-kwds-re)
(when (or (looking-at c-prefix-spec-kwds-re) (c-forward-type t))
(c-forward-type t)) ;; We've found another candidate position.
;; We've found another candidate position. (setq new-pos (min new-pos bo-decl))
(setq new-pos (min new-pos bo-decl)) (goto-char bo-decl))
(goto-char bo-decl)) t)
t) ;; Try and go out a level to search again.
;; Try and go out a level to search again. (progn
(progn (c-backward-syntactic-ws bod-lim)
(c-backward-syntactic-ws bod-lim) (and (> (point) bod-lim)
(and (> (point) bod-lim) (or (memq (char-before) '(?\( ?\[))
(or (memq (char-before) '(?\( ?\[)) (and (eq (char-before) ?\<)
(and (eq (char-before) ?\<) (eq (c-get-char-property
(eq (c-get-char-property (1- (point)) 'syntax-table)
(1- (point)) 'syntax-table) c-<-as-paren-syntax))
c-<-as-paren-syntax)) (and (eq (char-before) ?{)
(and (eq (char-before) ?{) (save-excursion
(save-excursion (backward-char)
(backward-char) (consp (c-looking-at-or-maybe-in-bracelist))))
(consp (c-looking-at-or-maybe-in-bracelist)))) )))
))) (not (bobp)))
(not (bobp))) (backward-char)) ; back over (, [, <.
(backward-char)) ; back over (, [, <. (when (and capture-opener (< capture-opener new-pos))
(when (and capture-opener (< capture-opener new-pos)) (setq new-pos capture-opener))
(setq new-pos capture-opener)) (and (/= new-pos pos) new-pos))))
(and (/= new-pos pos) new-pos)))
(defun c-fl-decl-end (pos) (defun c-fl-decl-end (pos)
;; If POS is inside a declarator, return the end of the token that follows ;; If POS is inside a declarator, return the end of the token that follows
;; the declarator, otherwise return nil. ;; the declarator, otherwise return nil. POS being in a literal does not
;; count as being in a declarator (on pragmatic grounds).
(goto-char pos) (goto-char pos)
(let ((lit-start (c-literal-start)) (let ((lit-start (c-literal-start))
pos1) pos1)
(if lit-start (goto-char lit-start)) (unless lit-start
(c-backward-syntactic-ws) (c-backward-syntactic-ws)
(when (setq pos1 (c-on-identifier)) (when (setq pos1 (c-on-identifier))
(goto-char pos1) (goto-char pos1)
(let ((lim (save-excursion (let ((lim (save-excursion
(and (c-beginning-of-macro) (and (c-beginning-of-macro)
(progn (c-end-of-macro) (point)))))) (progn (c-end-of-macro) (point))))))
(when (and (c-forward-declarator lim) (when (and (c-forward-declarator lim)
(or (not (eq (char-after) ?\()) (or (not (eq (char-after) ?\())
(c-go-list-forward nil lim)) (c-go-list-forward nil lim))
(eq (c-forward-token-2 1 nil lim) 0)) (eq (c-forward-token-2 1 nil lim) 0))
(c-backward-syntactic-ws) (c-backward-syntactic-ws)
(point)))))) (point)))))))
(defun c-change-expand-fl-region (_beg _end _old-len) (defun c-change-expand-fl-region (_beg _end _old-len)
;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock ;; Expand the region (c-new-BEG c-new-END) to an after-change font-lock
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment