diff options
| author | Alan Mackenzie | 2016-07-03 13:11:28 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-07-03 13:15:44 +0000 |
| commit | 4b9ac23960d2998f899287ffcf696ad33b63a69a (patch) | |
| tree | 5b79d1a842f7080c2d26f5d7d40cf7efdc0ec3b8 | |
| parent | b56a8bcd0e68451d0360ab6ed98c88d890324838 (diff) | |
| download | emacs-4b9ac23960d2998f899287ffcf696ad33b63a69a.tar.gz emacs-4b9ac23960d2998f899287ffcf696ad33b63a69a.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 67 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 5 |
2 files changed, 38 insertions, 34 deletions
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." | |||
| 1522 | (unless (or (eobp) | 1522 | (unless (or (eobp) |
| 1523 | (looking-at "\\s(\\|\\s)")) | 1523 | (looking-at "\\s(\\|\\s)")) |
| 1524 | (forward-char)) | 1524 | (forward-char)) |
| 1525 | (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) | 1525 | (c-syntactic-skip-backward "^;{}" decl-search-lim t) |
| 1526 | (if (and (eq bod-res 'same) | 1526 | (when (eq (char-before) ?}) |
| 1527 | (save-excursion | 1527 | (c-go-list-backward) ; brace block of struct, etc.? |
| 1528 | (c-backward-syntactic-ws) | 1528 | (c-syntactic-skip-backward "^;{}" decl-search-lim t)) |
| 1529 | (eq (char-before) ?\}))) | 1529 | (when (or (bobp) |
| 1530 | (c-beginning-of-decl-1 decl-search-lim)) | 1530 | (memq (char-before) '(?\; ?{ ?}))) |
| 1531 | 1531 | (c-forward-syntactic-ws) | |
| 1532 | ;; We're now putatively at the declaration. | 1532 | ;; We're now putatively at the declaration. |
| 1533 | (setq paren-state (c-parse-state)) | 1533 | (setq paren-state (c-parse-state)) |
| 1534 | ;; At top level or inside a "{"? | 1534 | ;; At top level or inside a "{"? |
| 1535 | (if (or (not (setq encl-pos | 1535 | (if (or (not (setq encl-pos |
| 1536 | (c-most-enclosing-brace paren-state))) | 1536 | (c-most-enclosing-brace paren-state))) |
| 1537 | (eq (char-after encl-pos) ?\{)) | 1537 | (eq (char-after encl-pos) ?\{)) |
| 1538 | (progn | 1538 | (progn |
| 1539 | (when (looking-at c-typedef-key) ; "typedef" | 1539 | (when (looking-at c-typedef-key) ; "typedef" |
| 1540 | (setq is-typedef t) | 1540 | (setq is-typedef t) |
| 1541 | (goto-char (match-end 0)) | 1541 | (goto-char (match-end 0)) |
| 1542 | (c-forward-syntactic-ws)) | 1542 | (c-forward-syntactic-ws)) |
| 1543 | ;; At a real declaration? | 1543 | ;; At a real declaration? |
| 1544 | (if (memq (c-forward-type t) '(t known found decltype)) | 1544 | (if (memq (c-forward-type t) '(t known found decltype)) |
| 1545 | (c-font-lock-declarators limit t is-typedef))) | 1545 | (c-font-lock-declarators limit t is-typedef))))))) |
| 1546 | nil))))) | 1546 | nil)) |
| 1547 | 1547 | ||
| 1548 | (defun c-font-lock-enclosing-decls (limit) | 1548 | (defun c-font-lock-enclosing-decls (limit) |
| 1549 | ;; Fontify the declarators of (nested) declarations we're in the middle of. | 1549 | ;; 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." | |||
| 1557 | ;; Fontification". | 1557 | ;; Fontification". |
| 1558 | (let* ((paren-state (c-parse-state)) | 1558 | (let* ((paren-state (c-parse-state)) |
| 1559 | (decl-search-lim (c-determine-limit 1000)) | 1559 | (decl-search-lim (c-determine-limit 1000)) |
| 1560 | decl-context in-typedef ps-elt) | 1560 | in-typedef ps-elt) |
| 1561 | ;; Are we in any nested struct/union/class/etc. braces? | 1561 | ;; Are we in any nested struct/union/class/etc. braces? |
| 1562 | (while paren-state | 1562 | (while paren-state |
| 1563 | (setq ps-elt (car paren-state) | 1563 | (setq ps-elt (car paren-state) |
| @@ -1565,15 +1565,18 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1565 | (when (and (atom ps-elt) | 1565 | (when (and (atom ps-elt) |
| 1566 | (eq (char-after ps-elt) ?\{)) | 1566 | (eq (char-after ps-elt) ?\{)) |
| 1567 | (goto-char ps-elt) | 1567 | (goto-char ps-elt) |
| 1568 | (setq decl-context (c-beginning-of-decl-1 decl-search-lim) | 1568 | (c-syntactic-skip-backward "^;{}" decl-search-lim) |
| 1569 | in-typedef (looking-at c-typedef-key)) | 1569 | (when (or (bobp) |
| 1570 | (if in-typedef (c-forward-token-2)) | 1570 | (memq (char-before) '(?\; ?}))) |
| 1571 | (when (and c-opt-block-decls-with-vars-key | 1571 | (c-forward-syntactic-ws) |
| 1572 | (looking-at c-opt-block-decls-with-vars-key)) | 1572 | (setq in-typedef (looking-at c-typedef-key)) |
| 1573 | (goto-char ps-elt) | 1573 | (if in-typedef (c-forward-token-2)) |
| 1574 | (when (c-safe (c-forward-sexp)) | 1574 | (when (and c-opt-block-decls-with-vars-key |
| 1575 | (c-forward-syntactic-ws) | 1575 | (looking-at c-opt-block-decls-with-vars-key)) |
| 1576 | (c-font-lock-declarators limit t in-typedef))))))) | 1576 | (goto-char ps-elt) |
| 1577 | (when (c-safe (c-forward-sexp)) | ||
| 1578 | (c-forward-syntactic-ws) | ||
| 1579 | (c-font-lock-declarators limit t in-typedef)))))))) | ||
| 1577 | 1580 | ||
| 1578 | (defun c-font-lock-raw-strings (limit) | 1581 | (defun c-font-lock-raw-strings (limit) |
| 1579 | ;; Fontify C++ raw strings. | 1582 | ;; 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." | |||
| 1310 | (while | 1310 | (while |
| 1311 | ;; Go to a less nested declaration each time round this loop. | 1311 | ;; Go to a less nested declaration each time round this loop. |
| 1312 | (and | 1312 | (and |
| 1313 | (eq (car (c-beginning-of-decl-1 bod-lim)) 'same) | 1313 | (c-syntactic-skip-backward "^;{}" bod-lim t) |
| 1314 | (> (point) bod-lim) | 1314 | (> (point) bod-lim) |
| 1315 | (progn (setq bo-decl (point)) | 1315 | (progn (c-forward-syntactic-ws) |
| 1316 | (setq bo-decl (point)) | ||
| 1316 | ;; Are we looking at a keyword such as "template" or | 1317 | ;; Are we looking at a keyword such as "template" or |
| 1317 | ;; "typedef" which can decorate a type, or the type itself? | 1318 | ;; "typedef" which can decorate a type, or the type itself? |
| 1318 | (when (or (looking-at c-prefix-spec-kwds-re) | 1319 | (when (or (looking-at c-prefix-spec-kwds-re) |