aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2012-03-16 14:10:54 +0000
committerAlan Mackenzie2012-03-16 14:10:54 +0000
commit2e492df3cdc46ce4f47aa93b548315d07616c626 (patch)
tree2b39e632f5a7ac2deac929a1978076bb5cd3419c
parent50e94f0c5da4a7560d821304124e9bd2962b4d6f (diff)
downloademacs-2e492df3cdc46ce4f47aa93b548315d07616c626.tar.gz
emacs-2e492df3cdc46ce4f47aa93b548315d07616c626.zip
Further optimise the handling of large macros.
-rw-r--r--lisp/ChangeLog17
-rw-r--r--lisp/progmodes/cc-engine.el57
-rw-r--r--lisp/progmodes/cc-mode.el4
3 files changed, 66 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 67ab591b7ea..867ca2dacde 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,20 @@
12012-03-16 Alan Mackenzie <acm@muc.de>
2
3 Further optimise the handling of large macros.
4
5 * progmodes/cc-engine.el (c-crosses-statement-barrier-p): Use a
6 limit to a call of `c-literal-limits'.
7 (c-determine-+ve-limit): New function.
8 (c-at-macro-vsemi-p): Move `c-in-literal' to the bottom of an
9 `and'.
10 (c-guess-basic-syntax): In macros, restrict a search limit to
11 2000.
12 In CASE 5B, restrict a search limit to 500.
13 (c-just-after-func-arglist-p): Obviouly wrong `or' -> `and'.
14
15 * progmodes/cc-mode.el (c-neutralize-syntax-in-and-mark-CPP):
16 Restrict macro bounds to +-500 from after-change's BEG END.
17
12012-03-16 Leo Liu <sdl.web@gmail.com> 182012-03-16 Leo Liu <sdl.web@gmail.com>
2 19
3 * font-lock.el (lisp-font-lock-keywords-2): Add letrec. 20 * font-lock.el (lisp-font-lock-keywords-2): Add letrec.
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index f392971e7d1..cf38001c123 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -1246,7 +1246,7 @@ comment at the start of cc-engine.el for more info."
1246 (c-at-vsemi-p)))) 1246 (c-at-vsemi-p))))
1247 (throw 'done vsemi-pos)) 1247 (throw 'done vsemi-pos))
1248 ;; In a string/comment? 1248 ;; In a string/comment?
1249 ((setq lit-range (c-literal-limits)) 1249 ((setq lit-range (c-literal-limits from))
1250 (goto-char (cdr lit-range))) 1250 (goto-char (cdr lit-range)))
1251 ((eq (char-after) ?:) 1251 ((eq (char-after) ?:)
1252 (forward-char) 1252 (forward-char)
@@ -3250,8 +3250,7 @@ comment at the start of cc-engine.el for more info."
3250 (if scan-forward-p 3250 (if scan-forward-p
3251 (progn (narrow-to-region (point-min) here) 3251 (progn (narrow-to-region (point-min) here)
3252 (c-append-to-state-cache good-pos)) 3252 (c-append-to-state-cache good-pos))
3253 3253 good-pos)))
3254 (c-get-cache-scan-pos good-pos))))
3255 3254
3256 (t ; (eq strategy 'IN-LIT) 3255 (t ; (eq strategy 'IN-LIT)
3257 (setq c-state-cache nil 3256 (setq c-state-cache nil
@@ -4563,6 +4562,38 @@ comment at the start of cc-engine.el for more info."
4563 (point-min)) 4562 (point-min))
4564 (t 4563 (t
4565 (c-determine-limit (- how-far-back count) base try-size)))))) 4564 (c-determine-limit (- how-far-back count) base try-size))))))
4565
4566(defun c-determine-+ve-limit (how-far &optional start-pos)
4567 ;; Return a buffer position about HOW-FAR non-literal characters forward
4568 ;; from START-POS (default point), which must not be inside a literal.
4569 (save-excursion
4570 (let ((pos (or start-pos (point)))
4571 (count how-far)
4572 (s (parse-partial-sexp (point) (point)))) ; null state
4573 (while (and (not (eobp))
4574 (> count 0))
4575 ;; Scan over counted characters.
4576 (setq s (parse-partial-sexp
4577 pos
4578 (min (+ pos count) (point-max))
4579 nil ; target-depth
4580 nil ; stop-before
4581 s ; state
4582 'syntax-table)) ; stop-comment
4583 (setq count (- count (- (point) pos) 1)
4584 pos (point))
4585 ;; Scan over literal characters.
4586 (if (nth 8 s)
4587 (setq s (parse-partial-sexp
4588 pos
4589 (point-max)
4590 nil ; target-depth
4591 nil ; stop-before
4592 s ; state
4593 'syntax-table) ; stop-comment
4594 pos (point))))
4595 (point))))
4596
4566 4597
4567;; `c-find-decl-spots' and accompanying stuff. 4598;; `c-find-decl-spots' and accompanying stuff.
4568 4599
@@ -7670,8 +7701,8 @@ comment at the start of cc-engine.el for more info."
7670 (and 7701 (and
7671 (eq (c-beginning-of-statement-1 lim) 'same) 7702 (eq (c-beginning-of-statement-1 lim) 'same)
7672 7703
7673 (not (or (c-major-mode-is 'objc-mode) 7704 (not (and (c-major-mode-is 'objc-mode)
7674 (c-forward-objc-directive))) 7705 (c-forward-objc-directive)))
7675 7706
7676 (setq id-start 7707 (setq id-start
7677 (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) nil nil))) 7708 (car-safe (c-forward-decl-or-cast-1 (c-point 'bosws) nil nil)))
@@ -8635,7 +8666,6 @@ comment at the start of cc-engine.el for more info."
8635 (setq pos (point))) 8666 (setq pos (point)))
8636 (and 8667 (and
8637 c-macro-with-semi-re 8668 c-macro-with-semi-re
8638 (not (c-in-literal))
8639 (eq (skip-chars-backward " \t") 0) 8669 (eq (skip-chars-backward " \t") 0)
8640 8670
8641 ;; Check we've got nothing after this except comments and empty lines 8671 ;; Check we've got nothing after this except comments and empty lines
@@ -8666,7 +8696,9 @@ comment at the start of cc-engine.el for more info."
8666 (c-backward-syntactic-ws) 8696 (c-backward-syntactic-ws)
8667 t)) 8697 t))
8668 (c-simple-skip-symbol-backward) 8698 (c-simple-skip-symbol-backward)
8669 (looking-at c-macro-with-semi-re))))) 8699 (looking-at c-macro-with-semi-re)
8700 (goto-char pos)
8701 (not (c-in-literal)))))) ; The most expensive check last.
8670 8702
8671(defun c-macro-vsemi-status-unknown-p () t) ; See cc-defs.el. 8703(defun c-macro-vsemi-status-unknown-p () t) ; See cc-defs.el.
8672 8704
@@ -9207,6 +9239,10 @@ comment at the start of cc-engine.el for more info."
9207 containing-sexp nil))) 9239 containing-sexp nil)))
9208 (setq lim (1+ containing-sexp)))) 9240 (setq lim (1+ containing-sexp))))
9209 (setq lim (point-min))) 9241 (setq lim (point-min)))
9242 (when (c-beginning-of-macro)
9243 (goto-char indent-point)
9244 (let ((lim1 (c-determine-limit 2000)))
9245 (setq lim (max lim lim1))))
9210 9246
9211 ;; If we're in a parenthesis list then ',' delimits the 9247 ;; If we're in a parenthesis list then ',' delimits the
9212 ;; "statements" rather than being an operator (with the 9248 ;; "statements" rather than being an operator (with the
@@ -9571,7 +9607,8 @@ comment at the start of cc-engine.el for more info."
9571 ;; CASE 5B: After a function header but before the body (or 9607 ;; CASE 5B: After a function header but before the body (or
9572 ;; the ending semicolon if there's no body). 9608 ;; the ending semicolon if there's no body).
9573 ((save-excursion 9609 ((save-excursion
9574 (when (setq placeholder (c-just-after-func-arglist-p lim)) 9610 (when (setq placeholder (c-just-after-func-arglist-p
9611 (max lim (c-determine-limit 500))))
9575 (setq tmp-pos (point)))) 9612 (setq tmp-pos (point))))
9576 (cond 9613 (cond
9577 9614
@@ -9779,7 +9816,7 @@ comment at the start of cc-engine.el for more info."
9779 ;; top level construct. Or, perhaps, an unrecognized construct. 9816 ;; top level construct. Or, perhaps, an unrecognized construct.
9780 (t 9817 (t
9781 (while (and (setq placeholder (point)) 9818 (while (and (setq placeholder (point))
9782 (eq (car (c-beginning-of-decl-1 containing-sexp)) 9819 (eq (car (c-beginning-of-decl-1 containing-sexp)) ; Can't use `lim' here.
9783 'same) 9820 'same)
9784 (save-excursion 9821 (save-excursion
9785 (c-backward-syntactic-ws) 9822 (c-backward-syntactic-ws)
@@ -9882,7 +9919,7 @@ comment at the start of cc-engine.el for more info."
9882 (eq (cdar c-state-cache) (point))) 9919 (eq (cdar c-state-cache) (point)))
9883 ;; Speed up the backward search a bit. 9920 ;; Speed up the backward search a bit.
9884 (goto-char (caar c-state-cache))) 9921 (goto-char (caar c-state-cache)))
9885 (c-beginning-of-decl-1 containing-sexp) 9922 (c-beginning-of-decl-1 containing-sexp) ; Can't use `lim' here.
9886 (setq placeholder (point)) 9923 (setq placeholder (point))
9887 (if (= start (point)) 9924 (if (= start (point))
9888 ;; The '}' is unbalanced. 9925 ;; The '}' is unbalanced.
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index 985214db1dc..7c018feefbb 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -925,8 +925,8 @@ Note that the style variables are always made local to the buffer."
925 ;; inside a string, comment, or macro. 925 ;; inside a string, comment, or macro.
926 (setq new-bounds (c-extend-font-lock-region-for-macros 926 (setq new-bounds (c-extend-font-lock-region-for-macros
927 c-new-BEG c-new-END old-len)) 927 c-new-BEG c-new-END old-len))
928 (setq c-new-BEG (car new-bounds) 928 (setq c-new-BEG (max (car new-bounds) (c-determine-limit 500 begg))
929 c-new-END (cdr new-bounds)) 929 c-new-END (min (cdr new-bounds) (c-determine-+ve-limit 500 endd)))
930 ;; Clear all old relevant properties. 930 ;; Clear all old relevant properties.
931 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1)) 931 (c-clear-char-property-with-value c-new-BEG c-new-END 'syntax-table '(1))
932 (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter) 932 (c-clear-char-property-with-value c-new-BEG c-new-END 'category 'c-cpp-delimiter)