emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b76385c: Speed up CC Mode's font locking by taking


From: Alan Mackenzie
Subject: [Emacs-diffs] master b76385c: Speed up CC Mode's font locking by taking some code out of a hot loop.
Date: Wed, 15 Jun 2016 22:07:52 +0000 (UTC)

branch: master
commit b76385c05076f0adaf7cf89d0ed95dfe5e8570e0
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Speed up CC Mode's font locking by taking some code out of a hot loop.
    
    * lisp/progmodes/cc-fonts.el (c-font-lock-declarations): Remove code which
    tests for bare declarators.
    (c-font-lock-cut-off-declarators): New function.
    (c-complex-decl-matchers): insert c-font-lock-cut-off-declarators.
---
 lisp/progmodes/cc-fonts.el |   88 +++++++++++++++++++++++---------------------
 1 file changed, 46 insertions(+), 42 deletions(-)

diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index f3f369f..65ec5c3 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -1447,48 +1447,7 @@ casts and declarations are fontified.  Used on level 2 
and higher."
                        (c-backward-over-enum-header)))))
              (c-forward-token-2)
              nil)
-
-            (t
-             ;; Are we at a declarator?  Try to go back to the declaration
-             ;; to check this.  If we get there, check whether a "typedef"
-             ;; is there, then fontify the declarators accordingly.
-             (let ((decl-search-lim (c-determine-limit 1000))
-                   paren-state bod-res encl-pos is-typedef
-                   c-recognize-knr-p) ; Strictly speaking, bogus, but it
-                                      ; speeds up lisp.h tremendously.
-               (save-excursion
-                 (if (c-back-over-member-initializers)
-                    t                  ; Can't be at a declarator
-                   (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))
-                             (progn
-                               (c-font-lock-declarators (point-max) t 
is-typedef)
-                               nil)
-                           ;; False alarm.  Return t to go on to the next 
check.
-                           (goto-char start-pos)
-                           t))
-                     t)))))))
+            (t t)))
 
          ;; It was a false alarm.  Check if we're in a label (or other
          ;; construct with `:' except bitfield) instead.
@@ -1545,6 +1504,47 @@ casts and declarations are fontified.  Used on level 2 
and higher."
       (c-font-lock-declarators limit t nil)))
   nil)
 
+(defun c-font-lock-cut-off-declarators (limit)
+  ;; Fontify any declarators "cut off" from their declaring type at the start
+  ;; of the region being fontified.
+  ;;
+  ;; This function will be called from font-lock- for a region bounded by
+  ;; POINT and LIMIT, as though it were to identify a keyword for
+  ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
+  ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
+  ;; fontification".
+  (let ((decl-search-lim (c-determine-limit 1000))
+       paren-state bod-res is-typedef encl-pos
+       c-recognize-knr-p)              ; Strictly speaking, bogus, but it
+                                       ; speeds up lisp.h tremendously.
+    (save-excursion
+      (when (not (c-back-over-member-initializers))
+       (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 (point-max) t is-typedef)))
+         nil)))))
+
 (defun c-font-lock-enclosing-decls (limit)
   ;; Fontify the declarators of (nested) declarations we're in the middle of.
   ;; This is mainly for when a jit-lock etc. chunk starts inside the brace
@@ -1715,6 +1715,10 @@ on level 2 only and so aren't combined with 
`c-complex-decl-matchers'."
                                       'c-type 'c-decl-end)))
              c-font-lock-objc-methods))
 
+      ;; Fontify declarators which have been cut off from their declaring
+      ;; types at the start of the region.
+      c-font-lock-cut-off-declarators
+
       ;; Fontify all declarations, casts and normal labels.
       c-font-lock-declarations
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]