Commit 8cff5feb authored by Alan Mackenzie's avatar Alan Mackenzie

Fix bugs in the c-parse-state mechanism. Reuse some markers instead of

continually generating new ones.

cc-engine.el (c-state-old-cpp-beg-marker, c-state-old-cpp-end-marker):
New variables.
(c-append-lower-brace-pair-to-state-cache): Start a backward search for
"}" definitively outside CPP constructs.
(c-remove-stale-state-cache): Inform the caller of a need to search back
for a brace pair in certain circumstances.
(c-state-maybe-marker): New macro.
(c-parse-state): Reuse markers when appropriate.
parent 45a7e57c
2013-01-09 Alan Mackenzie <acm@muc.de>
Fix bugs in the c-parse-state mechanism. Reuse some markers
instead of continually generating new ones.
* progmodes/cc-engine.el (c-state-old-cpp-beg-marker)
(c-state-old-cpp-end-marker): New variables.
(c-append-lower-brace-pair-to-state-cache): Start a backward
search for "}" definitively outside CPP constructs.
(c-remove-stale-state-cache): Inform the caller of a need to
search back for a brace pair in certain circumstances.
(c-state-maybe-marker): New macro.
(c-parse-state): Reuse markers when appropriate.
2013-01-09 Glenn Morris <rgm@gnu.org> 2013-01-09 Glenn Morris <rgm@gnu.org>
* simple.el (execute-extended-command): Doc fix. * simple.el (execute-extended-command): Doc fix.
......
...@@ -2464,8 +2464,12 @@ comment at the start of cc-engine.el for more info." ...@@ -2464,8 +2464,12 @@ comment at the start of cc-engine.el for more info."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables which keep track of preprocessor constructs. ;; Variables which keep track of preprocessor constructs.
(defvar c-state-old-cpp-beg-marker nil)
(make-variable-buffer-local 'c-state-old-cpp-beg-marker)
(defvar c-state-old-cpp-beg nil) (defvar c-state-old-cpp-beg nil)
(make-variable-buffer-local 'c-state-old-cpp-beg) (make-variable-buffer-local 'c-state-old-cpp-beg)
(defvar c-state-old-cpp-end-marker nil)
(make-variable-buffer-local 'c-state-old-cpp-end-marker)
(defvar c-state-old-cpp-end nil) (defvar c-state-old-cpp-end nil)
(make-variable-buffer-local 'c-state-old-cpp-end) (make-variable-buffer-local 'c-state-old-cpp-end)
;; These are the limits of the macro containing point at the previous call of ;; These are the limits of the macro containing point at the previous call of
...@@ -2653,13 +2657,21 @@ comment at the start of cc-engine.el for more info." ...@@ -2653,13 +2657,21 @@ comment at the start of cc-engine.el for more info."
;; reduce the time wasted in repeated fruitless searches in brace deserts. ;; reduce the time wasted in repeated fruitless searches in brace deserts.
(save-excursion (save-excursion
(save-restriction (save-restriction
(let ((bra from) ce ; Positions of "{" and "}". (let* (new-cons
new-cons (cache-pos (c-state-cache-top-lparen)) ; might be nil.
(cache-pos (c-state-cache-top-lparen)) ; might be nil. (macro-start-or-from
(macro-start-or-from (progn (goto-char from)
(progn (goto-char from) (c-beginning-of-macro)
(c-beginning-of-macro) (point)))
(point)))) (bra ; Position of "{".
;; Don't start scanning in the middle of a CPP construct unless
;; it contains HERE - these constructs, in Emacs, are "commented
;; out" with category properties.
(if (eq (c-get-char-property macro-start-or-from 'category)
'c-cpp-delimiter)
macro-start-or-from
from))
ce) ; Position of "}"
(or upper-lim (setq upper-lim from)) (or upper-lim (setq upper-lim from))
;; If we're essentially repeating a fruitless search, just give up. ;; If we're essentially repeating a fruitless search, just give up.
...@@ -2899,7 +2911,9 @@ comment at the start of cc-engine.el for more info." ...@@ -2899,7 +2911,9 @@ comment at the start of cc-engine.el for more info."
(point-max) (point-max)
(min (point-max) c-state-old-cpp-beg))) (min (point-max) c-state-old-cpp-beg)))
(while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim)) (while (and c-state-cache (>= (c-state-cache-top-lparen) upper-lim))
(setq scan-back-pos (car-safe (car c-state-cache)))
(setq c-state-cache (cdr c-state-cache))) (setq c-state-cache (cdr c-state-cache)))
;; If `upper-lim' is inside the last recorded brace pair, remove its ;; If `upper-lim' is inside the last recorded brace pair, remove its
;; RBrace and indicate we'll need to search backwards for a previous ;; RBrace and indicate we'll need to search backwards for a previous
;; brace pair. ;; brace pair.
...@@ -3324,6 +3338,13 @@ comment at the start of cc-engine.el for more info." ...@@ -3324,6 +3338,13 @@ comment at the start of cc-engine.el for more info."
(c-with-cpps-commented-out (c-with-cpps-commented-out
(c-invalidate-state-cache-1 here))))) (c-invalidate-state-cache-1 here)))))
(defmacro c-state-maybe-marker (place marker)
;; If PLACE is non-nil, return a marker marking it, otherwise nil.
;; We (re)use MARKER.
`(and ,place
(or ,marker (setq ,marker (make-marker)))
(set-marker ,marker ,place)))
(defun c-parse-state () (defun c-parse-state ()
;; This is a wrapper over `c-parse-state-1'. See that function for a ;; This is a wrapper over `c-parse-state-1'. See that function for a
;; description of the functionality and return value. ;; description of the functionality and return value.
...@@ -3350,9 +3371,10 @@ comment at the start of cc-engine.el for more info." ...@@ -3350,9 +3371,10 @@ comment at the start of cc-engine.el for more info."
(c-parse-state-1)) (c-parse-state-1))
(c-with-cpps-commented-out (c-with-cpps-commented-out
(c-parse-state-1)))) (c-parse-state-1))))
(setq c-state-old-cpp-beg (and here-cpp-beg (copy-marker here-cpp-beg t)) (setq c-state-old-cpp-beg
c-state-old-cpp-end (and here-cpp-end (copy-marker here-cpp-end t))) (c-state-maybe-marker here-cpp-beg c-state-old-cpp-beg-marker)
))) c-state-old-cpp-end
(c-state-maybe-marker here-cpp-end c-state-old-cpp-end-marker)))))
;; Debug tool to catch cache inconsistencies. This is called from ;; Debug tool to catch cache inconsistencies. This is called from
;; 000tests.el. ;; 000tests.el.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment