From: Alan Mackenzie Date: Sun, 3 Jul 2016 13:11:28 +0000 (+0000) Subject: Speed up CC Mode fontification with less accurate functions extending region X-Git-Tag: emacs-26.0.90~1840^2~127 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=4b9ac23960d2998f899287ffcf696ad33b63a69a;p=emacs.git Speed up CC Mode fontification with less accurate functions extending region * lisp/progmodes/cc-fonts.el (c-font-lock-cut-off-declarators) (c-font-lock-enclosing-decls) * lisp/progmodes/cc-mode.el (c-fl-decl-start): Replace invocations of c-beginning-of-decl-1 with less accurate invocations of c-syntactic-skip-backwards to speed up fontification. --- diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index 52f0b0d8696..f122a95feb5 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1522,28 +1522,28 @@ casts and declarations are fontified. Used on level 2 and higher." (unless (or (eobp) (looking-at "\\s(\\|\\s)")) (forward-char)) - (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) - (if (and (eq bod-res 'same) - (save-excursion - (c-backward-syntactic-ws) - (eq (char-before) ?\}))) - (c-beginning-of-decl-1 decl-search-lim)) - - ;; We're now putatively at the declaration. - (setq paren-state (c-parse-state)) - ;; At top level or inside a "{"? - (if (or (not (setq encl-pos - (c-most-enclosing-brace paren-state))) - (eq (char-after encl-pos) ?\{)) - (progn - (when (looking-at c-typedef-key) ; "typedef" - (setq is-typedef t) - (goto-char (match-end 0)) - (c-forward-syntactic-ws)) - ;; At a real declaration? - (if (memq (c-forward-type t) '(t known found decltype)) - (c-font-lock-declarators limit t is-typedef))) - nil))))) + (c-syntactic-skip-backward "^;{}" decl-search-lim t) + (when (eq (char-before) ?}) + (c-go-list-backward) ; brace block of struct, etc.? + (c-syntactic-skip-backward "^;{}" decl-search-lim t)) + (when (or (bobp) + (memq (char-before) '(?\; ?{ ?}))) + (c-forward-syntactic-ws) + ;; We're now putatively at the declaration. + (setq paren-state (c-parse-state)) + ;; At top level or inside a "{"? + (if (or (not (setq encl-pos + (c-most-enclosing-brace paren-state))) + (eq (char-after encl-pos) ?\{)) + (progn + (when (looking-at c-typedef-key) ; "typedef" + (setq is-typedef t) + (goto-char (match-end 0)) + (c-forward-syntactic-ws)) + ;; At a real declaration? + (if (memq (c-forward-type t) '(t known found decltype)) + (c-font-lock-declarators limit t is-typedef))))))) + nil)) (defun c-font-lock-enclosing-decls (limit) ;; Fontify the declarators of (nested) declarations we're in the middle of. @@ -1557,7 +1557,7 @@ casts and declarations are fontified. Used on level 2 and higher." ;; Fontification". (let* ((paren-state (c-parse-state)) (decl-search-lim (c-determine-limit 1000)) - decl-context in-typedef ps-elt) + in-typedef ps-elt) ;; Are we in any nested struct/union/class/etc. braces? (while paren-state (setq ps-elt (car paren-state) @@ -1565,15 +1565,18 @@ casts and declarations are fontified. Used on level 2 and higher." (when (and (atom ps-elt) (eq (char-after ps-elt) ?\{)) (goto-char ps-elt) - (setq decl-context (c-beginning-of-decl-1 decl-search-lim) - in-typedef (looking-at c-typedef-key)) - (if in-typedef (c-forward-token-2)) - (when (and c-opt-block-decls-with-vars-key - (looking-at c-opt-block-decls-with-vars-key)) - (goto-char ps-elt) - (when (c-safe (c-forward-sexp)) - (c-forward-syntactic-ws) - (c-font-lock-declarators limit t in-typedef))))))) + (c-syntactic-skip-backward "^;{}" decl-search-lim) + (when (or (bobp) + (memq (char-before) '(?\; ?}))) + (c-forward-syntactic-ws) + (setq in-typedef (looking-at c-typedef-key)) + (if in-typedef (c-forward-token-2)) + (when (and c-opt-block-decls-with-vars-key + (looking-at c-opt-block-decls-with-vars-key)) + (goto-char ps-elt) + (when (c-safe (c-forward-sexp)) + (c-forward-syntactic-ws) + (c-font-lock-declarators limit t in-typedef)))))))) (defun c-font-lock-raw-strings (limit) ;; Fontify C++ raw strings. diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 5ad7a010641..6711a02c93a 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -1310,9 +1310,10 @@ Note that the style variables are always made local to the buffer." (while ;; Go to a less nested declaration each time round this loop. (and - (eq (car (c-beginning-of-decl-1 bod-lim)) 'same) + (c-syntactic-skip-backward "^;{}" bod-lim t) (> (point) bod-lim) - (progn (setq bo-decl (point)) + (progn (c-forward-syntactic-ws) + (setq bo-decl (point)) ;; Are we looking at a keyword such as "template" or ;; "typedef" which can decorate a type, or the type itself? (when (or (looking-at c-prefix-spec-kwds-re)