]> code.delx.au - gnu-emacs/commitdiff
Speed up CC Mode fontification with less accurate functions extending region
authorAlan Mackenzie <acm@muc.de>
Sun, 3 Jul 2016 13:11:28 +0000 (13:11 +0000)
committerAlan Mackenzie <acm@muc.de>
Sun, 3 Jul 2016 13:15:44 +0000 (13:15 +0000)
* 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.

lisp/progmodes/cc-fonts.el
lisp/progmodes/cc-mode.el

index 52f0b0d86968b752a0c06c8da6ba21bbd8de0899..f122a95feb5a66bf9f4dc15bb445633d0da99014 100644 (file)
@@ -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.
index 5ad7a010641ce7f82f850b6ece67ab36369d4971..6711a02c93a987dc58db9feeb26bd2cd7b5902cd 100644 (file)
@@ -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)