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
......@@ -880,6 +880,9 @@ casts and declarations are fontified. Used on level 2 and higher."
(when (bobp)
(c-clear-found-types))
(c-skip-comments-and-strings limit)
(when (< (point) limit)
;; Clear the c-type char properties which mark the region, to recalculate
;; them properly. The most interesting properties are those put on the
;; closest token before the region.
......@@ -921,7 +924,7 @@ casts and declarations are fontified. Used on level 2 and higher."
(c-beginning-of-macro)
(looking-at c-cpp-expr-intro-re))
'in-cpp-expr)))
nil)
nil))
(defun c-font-lock-<>-arglists (limit)
;; This function will be called from font-lock for a region bounded by POINT
......@@ -936,6 +939,9 @@ casts and declarations are fontified. Used on level 2 and higher."
;;
;; This function might do hidden buffer changes.
(c-skip-comments-and-strings limit)
(when (< (point) limit)
(let (;; The font-lock package in Emacs is known to clobber
;; `parse-sexp-lookup-properties' (when it exists).
(parse-sexp-lookup-properties
......@@ -1002,7 +1008,7 @@ casts and declarations are fontified. Used on level 2 and higher."
'font-lock-type-face))))))
(goto-char pos)))
(goto-char pos)))))
(goto-char pos))))))
nil)
(defun c-font-lock-declarators (limit list types not-top
......@@ -1311,6 +1317,8 @@ casts and declarations are fontified. Used on level 2 and higher."
;; This function might do hidden buffer changes.
;;(message "c-font-lock-declarations search from %s to %s" (point) limit)
(c-skip-comments-and-strings limit)
(when (< (point) limit)
(save-restriction
(let (;; The position where `c-find-decl-spots' last stopped.
......@@ -1531,7 +1539,7 @@ casts and declarations are fontified. Used on level 2 and higher."
;; that.
t))))
nil)))
nil))))
(defun c-font-lock-enum-body (limit)
;; Fontify the identifiers of each enum we find by searching forward.
......@@ -1561,6 +1569,8 @@ casts and declarations are fontified. Used on level 2 and higher."
;;
;; Note that this function won't attempt to fontify beyond the end of the
;; current enum block, if any.
(c-skip-comments-and-strings limit)
(when (< (point) limit)
(let* ((paren-state (c-parse-state))
(encl-pos (c-most-enclosing-brace paren-state)))
(when (and
......@@ -1573,7 +1583,7 @@ casts and declarations are fontified. Used on level 2 and higher."
(c-put-char-property (1- (point)) 'c-type 'c-decl-id-start)
(c-forward-syntactic-ws)
(c-font-lock-declarators limit t nil t)))
(c-font-lock-declarators limit t nil t))))
nil)
(defun c-font-lock-cut-off-declarators (limit)
......@@ -1585,6 +1595,8 @@ casts and declarations are fontified. Used on level 2 and higher."
;; font-lock-keyword-face. It always returns NIL to inhibit this and
;; prevent a repeat invocation. See elisp/lispref page "Search-based
;; fontification".
(c-skip-comments-and-strings limit)
(when (< (point) limit)
(let ((here (point))
(decl-search-lim (c-determine-limit 1000))
paren-state encl-pos token-end context decl-or-cast
......@@ -1624,7 +1636,7 @@ casts and declarations are fontified. Used on level 2 and higher."
(goto-char start-pos)
(c-font-lock-single-decl limit decl-or-cast token-end
context top-level))))))))
nil))
nil)))
(defun c-font-lock-enclosing-decls (limit)
;; Fontify the declarators of (nested) declarations we're in the middle of.
......@@ -1636,6 +1648,8 @@ casts and declarations are fontified. Used on level 2 and higher."
;; font-lock-keyword-face. It always returns NIL to inhibit this and
;; prevent a repeat invocation. See elisp/lispref page "Search-based
;; Fontification".
(c-skip-comments-and-strings limit)
(when (< (point) limit)
(let* ((paren-state (c-parse-state))
(decl-search-lim (c-determine-limit 1000))
in-typedef ps-elt)
......@@ -1656,7 +1670,7 @@ casts and declarations are fontified. Used on level 2 and higher."
(when (c-safe (c-forward-sexp))
(c-forward-syntactic-ws)
(c-font-lock-declarators limit t in-typedef
(not (c-bs-at-toplevel-p (point))))))))))
(not (c-bs-at-toplevel-p (point)))))))))))
(defun c-font-lock-raw-strings (limit)
;; Fontify C++ raw strings.
......
......@@ -1192,8 +1192,6 @@ Note that the style variables are always made local to the buffer."
(beg-literal-type (and 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.
;; This could have the effect of flipping the meaning of any following
;; 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."
(when (and (eq beg-literal-type 'string)
(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-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....\".")
;; declaration is one which does not start outside of struct braces (and
;; 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
;; c-after-change (to prepare for after-change font-locking) or from font
;; lock context (etc.) fontification.
......@@ -1842,8 +1842,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
capture-opener
bod-lim bo-decl)
(goto-char (c-point 'bol new-pos))
(when lit-start ; Comment or string.
(goto-char lit-start))
(unless lit-start
(setq bod-lim (c-determine-limit 500))
;; In C++ Mode, first check if we are within a (possibly nested) lambda
......@@ -1907,15 +1906,16 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(backward-char)) ; back over (, [, <.
(when (and capture-opener (< capture-opener new-pos))
(setq new-pos capture-opener))
(and (/= new-pos pos) new-pos)))
(and (/= new-pos pos) new-pos))))
(defun c-fl-decl-end (pos)
;; 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)
(let ((lit-start (c-literal-start))
pos1)
(if lit-start (goto-char lit-start))
(unless lit-start
(c-backward-syntactic-ws)
(when (setq pos1 (c-on-identifier))
(goto-char pos1)
......@@ -1927,7 +1927,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(c-go-list-forward nil lim))
(eq (c-forward-token-2 1 nil lim) 0))
(c-backward-syntactic-ws)
(point))))))
(point)))))))
(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
......
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