diff options
| author | Alan Mackenzie | 2019-06-13 14:07:06 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2019-06-13 14:10:02 +0000 |
| commit | 6b5388794b4d1118cb4443cfccc1bdebb4fb1af4 (patch) | |
| tree | d1a275e19205e99c2fac595baa9fd67d9840ec09 | |
| parent | 38d8db1bf27a3e49a2181f57d7d3d92a06b69282 (diff) | |
| download | emacs-6b5388794b4d1118cb4443cfccc1bdebb4fb1af4.tar.gz emacs-6b5388794b4d1118cb4443cfccc1bdebb4fb1af4.zip | |
Depessimize bits of CC Mode for long C macros.
* lisp/progmodes/cc-engine.el (c-end-of-macro): Check for being in a
degenerate zero length "macro", when setting the macro cache.
(c-determine-+ve-limit): Add in a missing goto-char form for when start-pos is
non-nil.
(c-back-over-member-initializers): Add a search limit parameter.
* lisp/progmodes/cc-fonts.el (c-get-fontification-context): Add a search limit
to c-go-up-list-backward.
(c-font-lock-cut-off-declarators): Add a search limit to
c-back-over-member-initializers.
* lisp/progmodes/cc-mode.el (c-before-change-check-unbalanced-strings): Don't
set c-new-END to the end of logical line (which might be a long macro).
(c-after-change-mark-abnormal-strings): Calculate end-hwm in place of the
setting of c-new-END (above). Use this as a search limit rather than
c-new-END.
| -rw-r--r-- | lisp/progmodes/cc-engine.el | 76 | ||||
| -rw-r--r-- | lisp/progmodes/cc-fonts.el | 4 | ||||
| -rw-r--r-- | lisp/progmodes/cc-mode.el | 17 |
3 files changed, 56 insertions, 41 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el index b121529086a..eeb71002673 100644 --- a/lisp/progmodes/cc-engine.el +++ b/lisp/progmodes/cc-engine.el | |||
| @@ -380,6 +380,8 @@ comment at the start of cc-engine.el for more info." | |||
| 380 | nil))) | 380 | nil))) |
| 381 | 381 | ||
| 382 | (when (and (car c-macro-cache) | 382 | (when (and (car c-macro-cache) |
| 383 | (> (point) (car c-macro-cache)) ; in case we have a | ||
| 384 | ; zero-sized region. | ||
| 383 | (bolp) | 385 | (bolp) |
| 384 | (not (eq (char-before (1- (point))) ?\\))) | 386 | (not (eq (char-before (1- (point))) ?\\))) |
| 385 | (setcdr c-macro-cache (point)) | 387 | (setcdr c-macro-cache (point)) |
| @@ -5646,6 +5648,7 @@ comment at the start of cc-engine.el for more info." | |||
| 5646 | (let ((pos (or start-pos (point))) | 5648 | (let ((pos (or start-pos (point))) |
| 5647 | (count how-far) | 5649 | (count how-far) |
| 5648 | (s (parse-partial-sexp (point) (point)))) ; null state | 5650 | (s (parse-partial-sexp (point) (point)))) ; null state |
| 5651 | (goto-char pos) | ||
| 5649 | (while (and (not (eobp)) | 5652 | (while (and (not (eobp)) |
| 5650 | (> count 0)) | 5653 | (> count 0)) |
| 5651 | ;; Scan over counted characters. | 5654 | ;; Scan over counted characters. |
| @@ -8609,53 +8612,56 @@ comment at the start of cc-engine.el for more info." | |||
| 8609 | (throw 'level nil)) | 8612 | (throw 'level nil)) |
| 8610 | (c-backward-syntactic-ws))) | 8613 | (c-backward-syntactic-ws))) |
| 8611 | 8614 | ||
| 8612 | (defun c-back-over-member-initializers () | 8615 | (defun c-back-over-member-initializers (&optional limit) |
| 8613 | ;; Test whether we are in a C++ member initializer list, and if so, go back | 8616 | ;; Test whether we are in a C++ member initializer list, and if so, go back |
| 8614 | ;; to the introducing ":", returning the position of the opening paren of | 8617 | ;; to the introducing ":", returning the position of the opening paren of |
| 8615 | ;; the function's arglist. Otherwise return nil, leaving point unchanged. | 8618 | ;; the function's arglist. Otherwise return nil, leaving point unchanged. |
| 8616 | (let ((here (point)) | 8619 | ;; LIMIT, if non-nil, is a limit for the backward search. |
| 8617 | (paren-state (c-parse-state)) | 8620 | (save-restriction |
| 8618 | pos level-plausible at-top-level res) | 8621 | (if limit (narrow-to-region limit (point))) |
| 8619 | ;; Assume tentatively that we're at the top level. Try to go back to the | 8622 | (let ((here (point)) |
| 8620 | ;; colon we seek. | 8623 | (paren-state (c-parse-state)) |
| 8621 | (setq res | 8624 | pos level-plausible at-top-level res) |
| 8622 | (catch 'done | 8625 | ;; Assume tentatively that we're at the top level. Try to go back to the |
| 8623 | (setq level-plausible | 8626 | ;; colon we seek. |
| 8624 | (catch 'level | 8627 | (setq res |
| 8625 | (c-backward-syntactic-ws) | 8628 | (catch 'done |
| 8626 | (when (memq (char-before) '(?\) ?})) | ||
| 8627 | (when (not (c-go-list-backward)) | ||
| 8628 | (throw 'done nil)) | ||
| 8629 | (c-backward-syntactic-ws)) | ||
| 8630 | (when (c-back-over-compound-identifier) | ||
| 8631 | (c-backward-syntactic-ws)) | ||
| 8632 | (c-back-over-list-of-member-inits) | ||
| 8633 | (and (eq (char-before) ?:) | ||
| 8634 | (save-excursion | ||
| 8635 | (c-backward-token-2) | ||
| 8636 | (not (looking-at c-:$-multichar-token-regexp))) | ||
| 8637 | (c-just-after-func-arglist-p)))) | ||
| 8638 | |||
| 8639 | (while (and (not (and level-plausible | ||
| 8640 | (setq at-top-level (c-at-toplevel-p)))) | ||
| 8641 | (setq pos (c-pull-open-brace paren-state))) ; might be a paren. | ||
| 8642 | (setq level-plausible | 8629 | (setq level-plausible |
| 8643 | (catch 'level | 8630 | (catch 'level |
| 8644 | (goto-char pos) | ||
| 8645 | (c-backward-syntactic-ws) | ||
| 8646 | (when (not (c-back-over-compound-identifier)) | ||
| 8647 | (throw 'level nil)) | ||
| 8648 | (c-backward-syntactic-ws) | 8631 | (c-backward-syntactic-ws) |
| 8632 | (when (memq (char-before) '(?\) ?})) | ||
| 8633 | (when (not (c-go-list-backward)) | ||
| 8634 | (throw 'done nil)) | ||
| 8635 | (c-backward-syntactic-ws)) | ||
| 8636 | (when (c-back-over-compound-identifier) | ||
| 8637 | (c-backward-syntactic-ws)) | ||
| 8649 | (c-back-over-list-of-member-inits) | 8638 | (c-back-over-list-of-member-inits) |
| 8650 | (and (eq (char-before) ?:) | 8639 | (and (eq (char-before) ?:) |
| 8651 | (save-excursion | 8640 | (save-excursion |
| 8652 | (c-backward-token-2) | 8641 | (c-backward-token-2) |
| 8653 | (not (looking-at c-:$-multichar-token-regexp))) | 8642 | (not (looking-at c-:$-multichar-token-regexp))) |
| 8654 | (c-just-after-func-arglist-p))))) | 8643 | (c-just-after-func-arglist-p)))) |
| 8644 | |||
| 8645 | (while (and (not (and level-plausible | ||
| 8646 | (setq at-top-level (c-at-toplevel-p)))) | ||
| 8647 | (setq pos (c-pull-open-brace paren-state))) ; might be a paren. | ||
| 8648 | (setq level-plausible | ||
| 8649 | (catch 'level | ||
| 8650 | (goto-char pos) | ||
| 8651 | (c-backward-syntactic-ws) | ||
| 8652 | (when (not (c-back-over-compound-identifier)) | ||
| 8653 | (throw 'level nil)) | ||
| 8654 | (c-backward-syntactic-ws) | ||
| 8655 | (c-back-over-list-of-member-inits) | ||
| 8656 | (and (eq (char-before) ?:) | ||
| 8657 | (save-excursion | ||
| 8658 | (c-backward-token-2) | ||
| 8659 | (not (looking-at c-:$-multichar-token-regexp))) | ||
| 8660 | (c-just-after-func-arglist-p))))) | ||
| 8655 | 8661 | ||
| 8656 | (and at-top-level level-plausible))) | 8662 | (and at-top-level level-plausible))) |
| 8657 | (or res (goto-char here)) | 8663 | (or res (goto-char here)) |
| 8658 | res)) | 8664 | res))) |
| 8659 | 8665 | ||
| 8660 | (defun c-forward-class-decl () | 8666 | (defun c-forward-class-decl () |
| 8661 | "From the beginning of a struct/union, etc. move forward to | 8667 | "From the beginning of a struct/union, etc. move forward to |
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el index c3dd8f85bdc..cef2015f430 100644 --- a/lisp/progmodes/cc-fonts.el +++ b/lisp/progmodes/cc-fonts.el | |||
| @@ -1204,7 +1204,7 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1204 | ((save-excursion | 1204 | ((save-excursion |
| 1205 | (goto-char match-pos) | 1205 | (goto-char match-pos) |
| 1206 | (and (memq (char-before match-pos) '(?\( ?\,)) | 1206 | (and (memq (char-before match-pos) '(?\( ?\,)) |
| 1207 | (c-go-up-list-backward match-pos) | 1207 | (c-go-up-list-backward match-pos (c-determine-limit 500)) |
| 1208 | (eq (char-after) ?\() | 1208 | (eq (char-after) ?\() |
| 1209 | (let ((type (c-get-char-property (point) 'c-type))) | 1209 | (let ((type (c-get-char-property (point) 'c-type))) |
| 1210 | (or (memq type '(c-decl-arg-start c-decl-type-start)) | 1210 | (or (memq type '(c-decl-arg-start c-decl-type-start)) |
| @@ -1605,7 +1605,7 @@ casts and declarations are fontified. Used on level 2 and higher." | |||
| 1605 | c-recognize-knr-p) ; Strictly speaking, bogus, but it | 1605 | c-recognize-knr-p) ; Strictly speaking, bogus, but it |
| 1606 | ; speeds up lisp.h tremendously. | 1606 | ; speeds up lisp.h tremendously. |
| 1607 | (save-excursion | 1607 | (save-excursion |
| 1608 | (when (not (c-back-over-member-initializers)) | 1608 | (when (not (c-back-over-member-initializers (c-determine-limit 2000))) |
| 1609 | (unless (or (eobp) | 1609 | (unless (or (eobp) |
| 1610 | (looking-at "\\s(\\|\\s)")) | 1610 | (looking-at "\\s(\\|\\s)")) |
| 1611 | (forward-char)) | 1611 | (forward-char)) |
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el index 83c0e36167d..830dfcae27d 100644 --- a/lisp/progmodes/cc-mode.el +++ b/lisp/progmodes/cc-mode.el | |||
| @@ -1256,7 +1256,6 @@ Note that the style variables are always made local to the buffer." | |||
| 1256 | (re-search-forward "[\n\r]?\\(\\\\\\(.\\|\n\\)\\|[^\\\n\r]\\)*" | 1256 | (re-search-forward "[\n\r]?\\(\\\\\\(.\\|\n\\)\\|[^\\\n\r]\\)*" |
| 1257 | nil t) | 1257 | nil t) |
| 1258 | ;; We're at an EOLL or point-max. | 1258 | ;; We're at an EOLL or point-max. |
| 1259 | (setq c-new-END (max c-new-END (min (1+ (point)) (point-max)))) | ||
| 1260 | (if (equal (c-get-char-property (point) 'syntax-table) '(15)) | 1259 | (if (equal (c-get-char-property (point) 'syntax-table) '(15)) |
| 1261 | (if (memq (char-after) '(?\n ?\r)) | 1260 | (if (memq (char-after) '(?\n ?\r)) |
| 1262 | ;; Normally terminated invalid string. | 1261 | ;; Normally terminated invalid string. |
| @@ -1363,6 +1362,16 @@ Note that the style variables are always made local to the buffer." | |||
| 1363 | (cdr (assq (char-before) c-string-innards-re-alist)) nil t) | 1362 | (cdr (assq (char-before) c-string-innards-re-alist)) nil t) |
| 1364 | (1+ (point))))) | 1363 | (1+ (point))))) |
| 1365 | (cll))) | 1364 | (cll))) |
| 1365 | (end-hwm ; the highest position which could possibly be affected by | ||
| 1366 | ; insertion/deletion of string delimiters. | ||
| 1367 | (max | ||
| 1368 | (progn | ||
| 1369 | (goto-char (min (1+ end) ; 1+, in case a NL has become escaped. | ||
| 1370 | (point-max))) | ||
| 1371 | (re-search-forward "\\(\\\\\\(.\\|\n\\|\r\\)\\|[^\\\n\r]\\)*" | ||
| 1372 | nil t) | ||
| 1373 | (point)) | ||
| 1374 | c-new-END)) | ||
| 1366 | s) | 1375 | s) |
| 1367 | (goto-char | 1376 | (goto-char |
| 1368 | (cond ((null beg-literal-type) | 1377 | (cond ((null beg-literal-type) |
| @@ -1374,13 +1383,13 @@ Note that the style variables are always made local to the buffer." | |||
| 1374 | ;; Handle one string each time around the next while loop. | 1383 | ;; Handle one string each time around the next while loop. |
| 1375 | (while | 1384 | (while |
| 1376 | (and | 1385 | (and |
| 1377 | (< (point) c-new-END) | 1386 | (< (point) end-hwm) |
| 1378 | (progn | 1387 | (progn |
| 1379 | ;; Skip over any comments before the next string. | 1388 | ;; Skip over any comments before the next string. |
| 1380 | (while (progn | 1389 | (while (progn |
| 1381 | (setq s (parse-partial-sexp (point) c-new-END nil | 1390 | (setq s (parse-partial-sexp (point) end-hwm nil |
| 1382 | nil s 'syntax-table)) | 1391 | nil s 'syntax-table)) |
| 1383 | (and (< (point) c-new-END) | 1392 | (and (< (point) end-hwm) |
| 1384 | (or (not (nth 3 s)) | 1393 | (or (not (nth 3 s)) |
| 1385 | (not (memq (char-before) c-string-delims)))))) | 1394 | (not (memq (char-before) c-string-delims)))))) |
| 1386 | ;; We're at the start of a string. | 1395 | ;; We're at the start of a string. |