diff options
| author | Alan Mackenzie | 2016-06-15 22:06:14 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2016-06-15 22:06:14 +0000 |
| commit | b76385c05076f0adaf7cf89d0ed95dfe5e8570e0 (patch) | |
| tree | 2bea04ca5603718acab3690fa16c249ba19d18f3 | |
| parent | fd8084aaf925a52754e01f69f4b6c5593be0982d (diff) | |
| download | emacs-b76385c05076f0adaf7cf89d0ed95dfe5e8570e0.tar.gz emacs-b76385c05076f0adaf7cf89d0ed95dfe5e8570e0.zip | |
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.
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 88 |
1 files changed, 46 insertions, 42 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index f3f369f5f8c..65ec5c3f044 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." | |||
| 1447 | (c-backward-over-enum-header))))) | 1447 | (c-backward-over-enum-header))))) |
| 1448 | (c-forward-token-2) | 1448 | (c-forward-token-2) |
| 1449 | nil) | 1449 | nil) |
| 1450 | 1450 | (t t))) | |
| 1451 | (t | ||
| 1452 | ;; Are we at a declarator? Try to go back to the declaration | ||
| 1453 | ;; to check this. If we get there, check whether a "typedef" | ||
| 1454 | ;; is there, then fontify the declarators accordingly. | ||
| 1455 | (let ((decl-search-lim (c-determine-limit 1000)) | ||
| 1456 | paren-state bod-res encl-pos is-typedef | ||
| 1457 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | ||
| 1458 | ; speeds up lisp.h tremendously. | ||
| 1459 | (save-excursion | ||
| 1460 | (if (c-back-over-member-initializers) | ||
| 1461 | t ; Can't be at a declarator | ||
| 1462 | (unless (or (eobp) | ||
| 1463 | (looking-at "\\s(\\|\\s)")) | ||
| 1464 | (forward-char)) | ||
| 1465 | (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) | ||
| 1466 | (if (and (eq bod-res 'same) | ||
| 1467 | (save-excursion | ||
| 1468 | (c-backward-syntactic-ws) | ||
| 1469 | (eq (char-before) ?\}))) | ||
| 1470 | (c-beginning-of-decl-1 decl-search-lim)) | ||
| 1471 | |||
| 1472 | ;; We're now putatively at the declaration. | ||
| 1473 | (setq paren-state (c-parse-state)) | ||
| 1474 | ;; At top level or inside a "{"? | ||
| 1475 | (if (or (not (setq encl-pos | ||
| 1476 | (c-most-enclosing-brace paren-state))) | ||
| 1477 | (eq (char-after encl-pos) ?\{)) | ||
| 1478 | (progn | ||
| 1479 | (when (looking-at c-typedef-key) ; "typedef" | ||
| 1480 | (setq is-typedef t) | ||
| 1481 | (goto-char (match-end 0)) | ||
| 1482 | (c-forward-syntactic-ws)) | ||
| 1483 | ;; At a real declaration? | ||
| 1484 | (if (memq (c-forward-type t) '(t known found decltype)) | ||
| 1485 | (progn | ||
| 1486 | (c-font-lock-declarators (point-max) t is-typedef) | ||
| 1487 | nil) | ||
| 1488 | ;; False alarm. Return t to go on to the next check. | ||
| 1489 | (goto-char start-pos) | ||
| 1490 | t)) | ||
| 1491 | t))))))) | ||
| 1492 | 1451 | ||
| 1493 | ;; It was a false alarm. Check if we're in a label (or other | 1452 | ;; It was a false alarm. Check if we're in a label (or other |
| 1494 | ;; construct with `:' except bitfield) instead. | 1453 | ;; construct with `:' except bitfield) instead. |
| @@ -1545,6 +1504,47 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1545 | (c-font-lock-declarators limit t nil))) | 1504 | (c-font-lock-declarators limit t nil))) |
| 1546 | nil) | 1505 | nil) |
| 1547 | 1506 | ||
| 1507 | (defun c-font-lock-cut-off-declarators (limit) | ||
| 1508 | ;; Fontify any declarators "cut off" from their declaring type at the start | ||
| 1509 | ;; of the region being fontified. | ||
| 1510 | ;; | ||
| 1511 | ;; This function will be called from font-lock- for a region bounded by | ||
| 1512 | ;; POINT and LIMIT, as though it were to identify a keyword for | ||
| 1513 | ;; font-lock-keyword-face. It always returns NIL to inhibit this and | ||
| 1514 | ;; prevent a repeat invocation. See elisp/lispref page "Search-based | ||
| 1515 | ;; fontification". | ||
| 1516 | (let ((decl-search-lim (c-determine-limit 1000)) | ||
| 1517 | paren-state bod-res is-typedef encl-pos | ||
| 1518 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | ||
| 1519 | ; speeds up lisp.h tremendously. | ||
| 1520 | (save-excursion | ||
| 1521 | (when (not (c-back-over-member-initializers)) | ||
| 1522 | (unless (or (eobp) | ||
| 1523 | (looking-at "\\s(\\|\\s)")) | ||
| 1524 | (forward-char)) | ||
| 1525 | (setq bod-res (car (c-beginning-of-decl-1 decl-search-lim))) | ||
| 1526 | (if (and (eq bod-res 'same) | ||
| 1527 | (save-excursion | ||
| 1528 | (c-backward-syntactic-ws) | ||
| 1529 | (eq (char-before) ?\}))) | ||
| 1530 | (c-beginning-of-decl-1 decl-search-lim)) | ||
| 1531 | |||
| 1532 | ;; We're now putatively at the declaration. | ||
| 1533 | (setq paren-state (c-parse-state)) | ||
| 1534 | ;; At top level or inside a "{"? | ||
| 1535 | (if (or (not (setq encl-pos | ||
| 1536 | (c-most-enclosing-brace paren-state))) | ||
| 1537 | (eq (char-after encl-pos) ?\{)) | ||
| 1538 | (progn | ||
| 1539 | (when (looking-at c-typedef-key) ; "typedef" | ||
| 1540 | (setq is-typedef t) | ||
| 1541 | (goto-char (match-end 0)) | ||
| 1542 | (c-forward-syntactic-ws)) | ||
| 1543 | ;; At a real declaration? | ||
| 1544 | (if (memq (c-forward-type t) '(t known found decltype)) | ||
| 1545 | (c-font-lock-declarators (point-max) t is-typedef))) | ||
| 1546 | nil))))) | ||
| 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. |
| 1550 | ;; This is mainly for when a jit-lock etc. chunk starts inside the brace | 1550 | ;; 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'." | |||
| 1715 | 'c-type 'c-decl-end))) | 1715 | 'c-type 'c-decl-end))) |
| 1716 | c-font-lock-objc-methods)) | 1716 | c-font-lock-objc-methods)) |
| 1717 | 1717 | ||
| 1718 | ;; Fontify declarators which have been cut off from their declaring | ||
| 1719 | ;; types at the start of the region. | ||
| 1720 | c-font-lock-cut-off-declarators | ||
| 1721 | |||
| 1718 | ;; Fontify all declarations, casts and normal labels. | 1722 | ;; Fontify all declarations, casts and normal labels. |
| 1719 | c-font-lock-declarations | 1723 | c-font-lock-declarations |
| 1720 | 1724 | ||