emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/emacs-24 r111162: Fix bugs in the c-parse-s


From: Alan Mackenzie
Subject: [Emacs-diffs] /srv/bzr/emacs/emacs-24 r111162: Fix bugs in the c-parse-state mechanism. Reuse some markers instead of
Date: Wed, 09 Jan 2013 21:33:00 +0000
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 111162
committer: Alan Mackenzie <address@hidden>
branch nick: emacs-24
timestamp: Wed 2013-01-09 21:33:00 +0000
message:
  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.
modified:
  lisp/ChangeLog
  lisp/progmodes/cc-engine.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2013-01-09 21:23:14 +0000
+++ b/lisp/ChangeLog    2013-01-09 21:33:00 +0000
@@ -1,3 +1,17 @@
+2013-01-09  Alan Mackenzie  <address@hidden>
+
+       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  <address@hidden>
 
        * simple.el (execute-extended-command): Doc fix.

=== modified file 'lisp/progmodes/cc-engine.el'
--- a/lisp/progmodes/cc-engine.el       2013-01-01 09:11:05 +0000
+++ b/lisp/progmodes/cc-engine.el       2013-01-09 21:33:00 +0000
@@ -2464,8 +2464,12 @@
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; 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)
 (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)
 (make-variable-buffer-local 'c-state-old-cpp-end)
 ;; These are the limits of the macro containing point at the previous call of
@@ -2653,13 +2657,21 @@
   ;; reduce the time wasted in repeated fruitless searches in brace deserts.
   (save-excursion
     (save-restriction
-      (let ((bra from) ce              ; Positions of "{" and "}".
-           new-cons
-           (cache-pos (c-state-cache-top-lparen)) ; might be nil.
-           (macro-start-or-from
-            (progn (goto-char from)
-                   (c-beginning-of-macro)
-                   (point))))
+      (let* (new-cons
+            (cache-pos (c-state-cache-top-lparen)) ; might be nil.
+            (macro-start-or-from
+             (progn (goto-char from)
+                    (c-beginning-of-macro)
+                    (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))
 
        ;; If we're essentially repeating a fruitless search, just give up.
@@ -2899,7 +2911,9 @@
                  (point-max)
                (min (point-max) c-state-old-cpp-beg)))
        (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)))
+
        ;; If `upper-lim' is inside the last recorded brace pair, remove its
        ;; RBrace and indicate we'll need to search backwards for a previous
        ;; brace pair.
@@ -3324,6 +3338,13 @@
      (c-with-cpps-commented-out
       (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 ()
   ;; This is a wrapper over `c-parse-state-1'.  See that function for a
   ;; description of the functionality and return value.
@@ -3350,9 +3371,10 @@
              (c-parse-state-1))
           (c-with-cpps-commented-out
            (c-parse-state-1))))
-      (setq c-state-old-cpp-beg (and here-cpp-beg (copy-marker here-cpp-beg t))
-           c-state-old-cpp-end (and here-cpp-end (copy-marker here-cpp-end t)))
-      )))
+      (setq c-state-old-cpp-beg
+           (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
 ;; 000tests.el.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]