From 9d5a8f0b3c3fe959d307d5b2f106943aa970c59b Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sun, 8 Jan 2012 12:49:44 +0000 Subject: [PATCH] Optimise font locking in long enum definitions. --- lisp/ChangeLog | 9 +++++++++ lisp/progmodes/cc-fonts.el | 15 +++++++++++++++ lisp/progmodes/cc-langs.el | 6 ++++++ lisp/progmodes/cc-mode.el | 2 +- 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9e490a1e367..ab8572b7f93 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +2012-01-08 Alan Mackenzie + + Optimise font locking in long enum definitions. + + * progmodes/cc-fonts.el (c-font-lock-declarations): Add an extra + arm to a cond form to handle enums. + * progmodes/cc-langs.el (c-enums-contain-decls): New lang variable. + * progmodes/cc-mode.el (c-font-lock-fontify-region): Correct a typo. + 2012-01-07 Paul Eggert * files.el (move-file-to-trash): Preserve default file modes on error. diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index ee5fb1bd086..f52864df809 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el @@ -1428,6 +1428,21 @@ casts and declarations are fontified. Used on level 2 and higher." (c-fontify-recorded-types-and-refs) nil) + ((and (not c-enums-contain-decls) + ;; An optimisation quickly to eliminate scans of long enum + ;; declarations in the next cond arm. + (let ((paren-state (c-parse-state))) + (and + (numberp (car paren-state)) + (save-excursion + (goto-char (car paren-state)) + (c-backward-token-2) + (or (looking-at c-brace-list-key) + (progn + (c-backward-token-2) + (looking-at c-brace-list-key))))))) + t) + (t ;; Are we at a declarator? Try to go back to the declaration ;; to check this. If we get there, check whether a "typedef" diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index b565cf98b3c..fafbfb70552 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el @@ -2938,6 +2938,12 @@ expression is considered to be a type." (consp (c-lang-const c-<>-arglist-kwds)))) (c-lang-defvar c-recognize-<>-arglists (c-lang-const c-recognize-<>-arglists)) +(c-lang-defconst c-enums-contain-decls + "Non-nil means that an enum structure can contain declarations." + t nil + java t) +(c-lang-defvar c-enums-contain-decls (c-lang-const c-enums-contain-decls)) + (c-lang-defconst c-recognize-paren-inits "Non-nil means that parenthesis style initializers exist, i.e. constructs like diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 600d4fc8b56..b74d878516d 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el @@ -1158,7 +1158,7 @@ Note that the style variables are always made local to the buffer." ;; Effectively advice around `font-lock-fontify-region' which extends the ;; region (BEG END), for example, to avoid context fontification chopping ;; off the start of the context. Do not do anything if it's already been - ;; done (i.e. from and after-change fontification. An example (C++) where + ;; done (i.e. from an after-change fontification. An example (C++) where ;; this used to happen is this: ;; ;; template -- 2.11.4.GIT