aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2019-06-01 20:15:13 +0000
committerAlan Mackenzie2019-06-01 20:15:13 +0000
commitbd5ca5597981949f0c8cac4e8844c7c56de15c51 (patch)
treeebb9de4e812ff16dd5c1cbd7a7b5feaeb7d864cb
parent99bc4af9c883d0faa5a1387cb26c1cbf09feb958 (diff)
downloademacs-bd5ca5597981949f0c8cac4e8844c7c56de15c51.tar.gz
emacs-bd5ca5597981949f0c8cac4e8844c7c56de15c51.zip
Debug and disentangle the literal cacheing in CC Mode
(Final Commit) * lisp/progmodes/cc-engine.el (c-semi-trim-near-cache): Correct a comparison with the wrong ...-limit variable. (c-semi-pp-to-literal): Remove a wrong setting of c-lit-pos-cache-limit. (c-full-get-near-cache-entry): Eliminate extravagant and unneeded coding. (c-state-cache-init, c-record-parse-state-state): No longer manipulate c-lit-pos-cache, which is no longer regarded as part of c-parse-state. * lisp/progmodes/cc-mode.el (c-basic-common-init): Call c-truncate-lit-pos-cache to initialize the literal cache.
-rw-r--r--lisp/progmodes/cc-engine.el55
-rw-r--r--lisp/progmodes/cc-mode.el2
2 files changed, 24 insertions, 33 deletions
diff --git a/lisp/progmodes/cc-engine.el b/lisp/progmodes/cc-engine.el
index 337271b2e67..13b38b439a1 100644
--- a/lisp/progmodes/cc-engine.el
+++ b/lisp/progmodes/cc-engine.el
@@ -2713,7 +2713,7 @@ comment at the start of cc-engine.el for more info."
2713 ;; whose positions are above `c-lit-pos-cache-limit'. 2713 ;; whose positions are above `c-lit-pos-cache-limit'.
2714 (let ((nc-list c-semi-lit-near-cache)) 2714 (let ((nc-list c-semi-lit-near-cache))
2715 (while nc-list 2715 (while nc-list
2716 (if (> (caar nc-list) c-lit-pos-cache-limit) 2716 (if (> (caar nc-list) c-semi-near-cache-limit)
2717 (setq c-semi-lit-near-cache 2717 (setq c-semi-lit-near-cache
2718 (delq (car nc-list) c-semi-lit-near-cache) 2718 (delq (car nc-list) c-semi-lit-near-cache)
2719 nc-list c-semi-lit-near-cache) ; start again in case 2719 nc-list c-semi-lit-near-cache) ; start again in case
@@ -2781,7 +2781,6 @@ comment at the start of cc-engine.el for more info."
2781 (widen) 2781 (widen)
2782 (c-trim-lit-pos-cache) 2782 (c-trim-lit-pos-cache)
2783 (c-semi-trim-near-cache) 2783 (c-semi-trim-near-cache)
2784 (setq c-lit-pos-cache-limit here)
2785 (save-match-data 2784 (save-match-data
2786 (let* ((pos-and-state (c-semi-get-near-cache-entry here)) 2785 (let* ((pos-and-state (c-semi-get-near-cache-entry here))
2787 (pos (car pos-and-state)) 2786 (pos (car pos-and-state))
@@ -2849,9 +2848,8 @@ comment at the start of cc-engine.el for more info."
2849;; END is the end of the literal enclosing HERE, if any, or nil otherwise. 2848;; END is the end of the literal enclosing HERE, if any, or nil otherwise.
2850 2849
2851(defun c-full-trim-near-cache () 2850(defun c-full-trim-near-cache ()
2852 ;; Remove stale entries in `c-full-lit-near-cache', i.e. those 2851 ;; Remove stale entries in `c-full-lit-near-cache', i.e. those whose END
2853 ;; whose END entries, or positions, are above 2852 ;; entries, or positions, are above `c-full-near-cache-limit'.
2854 ;; `c-state-full-nonlit-pos-cache-limit'.
2855 (let ((nc-list c-full-lit-near-cache) elt) 2853 (let ((nc-list c-full-lit-near-cache) elt)
2856 (while nc-list 2854 (while nc-list
2857 (let ((elt (car nc-list))) 2855 (let ((elt (car nc-list)))
@@ -2873,24 +2871,22 @@ comment at the start of cc-engine.el for more info."
2873 (let ((nc-pos-state 2871 (let ((nc-pos-state
2874 (or (assq here c-full-lit-near-cache) 2872 (or (assq here c-full-lit-near-cache)
2875 (let ((nc-list c-full-lit-near-cache) 2873 (let ((nc-list c-full-lit-near-cache)
2876 elt match (nc-pos 0) cand-pos-state) 2874 elt (nc-pos 0) cand-pos-state)
2877 (setq match 2875 (catch 'found
2878 (catch 'found 2876 (while nc-list
2879 (while nc-list 2877 (setq elt (car nc-list))
2880 (setq elt (car nc-list)) 2878 (when
2881 (when 2879 (and (car (cddr elt))
2882 (and (car (cddr elt)) 2880 (>= here (nth 8 (cadr elt)))
2883 (>= here (nth 8 (cadr elt))) 2881 (< here (car (cddr elt))))
2884 (< here (car (cddr elt)))) 2882 (throw 'found elt))
2885 (throw 'found elt)) 2883 (when
2886 (when 2884 (and (< (car elt) here)
2887 (and (< (car elt) here) 2885 (> (car elt) nc-pos))
2888 (> (car elt) nc-pos)) 2886 (setq nc-pos (car elt)
2889 (setq nc-pos (car elt) 2887 cand-pos-state elt))
2890 cand-pos-state elt)) 2888 (setq nc-list (cdr nc-list)))
2891 (setq nc-list (cdr nc-list))) 2889 cand-pos-state)))))
2892 nil))
2893 (or match cand-pos-state)))))
2894 ;; Move the found cache entry, if any, to the front of the list. 2890 ;; Move the found cache entry, if any, to the front of the list.
2895 (when (and nc-pos-state 2891 (when (and nc-pos-state
2896 (not (eq nc-pos-state (car c-full-lit-near-cache)))) 2892 (not (eq nc-pos-state (car c-full-lit-near-cache))))
@@ -3005,12 +3001,9 @@ comment at the start of cc-engine.el for more info."
3005(defsubst c-truncate-lit-pos-cache (pos) 3001(defsubst c-truncate-lit-pos-cache (pos)
3006 ;; Truncate the upper bound of each of the three caches to POS, if it is 3002 ;; Truncate the upper bound of each of the three caches to POS, if it is
3007 ;; higher than that position. 3003 ;; higher than that position.
3008 (setq c-lit-pos-cache-limit 3004 (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos)
3009 (min c-lit-pos-cache-limit pos) 3005 c-semi-near-cache-limit (min c-semi-near-cache-limit pos)
3010 c-semi-near-cache-limit 3006 c-full-near-cache-limit (min c-full-near-cache-limit pos)))
3011 (min c-semi-near-cache-limit pos)
3012 c-full-near-cache-limit
3013 (min c-full-near-cache-limit pos)))
3014 3007
3015 3008
3016;; A system for finding noteworthy parens before the point. 3009;; A system for finding noteworthy parens before the point.
@@ -4044,8 +4037,6 @@ comment at the start of cc-engine.el for more info."
4044 c-state-cache-good-pos 1 4037 c-state-cache-good-pos 1
4045 c-state-nonlit-pos-cache nil 4038 c-state-nonlit-pos-cache nil
4046 c-state-nonlit-pos-cache-limit 1 4039 c-state-nonlit-pos-cache-limit 1
4047 c-lit-pos-cache nil
4048 c-lit-pos-cache-limit 1
4049 c-state-brace-pair-desert nil 4040 c-state-brace-pair-desert nil
4050 c-state-point-min 1 4041 c-state-point-min 1
4051 c-state-point-min-lit-type nil 4042 c-state-point-min-lit-type nil
@@ -4320,8 +4311,6 @@ comment at the start of cc-engine.el for more info."
4320 c-state-cache-good-pos 4311 c-state-cache-good-pos
4321 c-state-nonlit-pos-cache 4312 c-state-nonlit-pos-cache
4322 c-state-nonlit-pos-cache-limit 4313 c-state-nonlit-pos-cache-limit
4323 c-lit-pos-cache
4324 c-lit-pos-cache-limit
4325 c-state-brace-pair-desert 4314 c-state-brace-pair-desert
4326 c-state-point-min 4315 c-state-point-min
4327 c-state-point-min-lit-type 4316 c-state-point-min-lit-type
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index c4b2d7bd5dc..6afcb08a7ca 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -559,6 +559,8 @@ that requires a literal mode spec at compile time."
559 ;; doesn't work with filladapt but it's better than nothing. 559 ;; doesn't work with filladapt but it's better than nothing.
560 (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph) 560 (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph)
561 561
562 ;; Initialize the three literal sub-caches.
563 (c-truncate-lit-pos-cache 1)
562 ;; Initialize the cache of brace pairs, and opening braces/brackets/parens. 564 ;; Initialize the cache of brace pairs, and opening braces/brackets/parens.
563 (c-state-cache-init) 565 (c-state-cache-init)
564 ;; Initialize the "brace stack" cache. 566 ;; Initialize the "brace stack" cache.