From bd5ca5597981949f0c8cac4e8844c7c56de15c51 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sat, 1 Jun 2019 20:15:13 +0000 Subject: [PATCH] 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. --- lisp/progmodes/cc-engine.el | 55 +++++++++++++++---------------------- lisp/progmodes/cc-mode.el | 2 ++ 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." ;; whose positions are above `c-lit-pos-cache-limit'. (let ((nc-list c-semi-lit-near-cache)) (while nc-list - (if (> (caar nc-list) c-lit-pos-cache-limit) + (if (> (caar nc-list) c-semi-near-cache-limit) (setq c-semi-lit-near-cache (delq (car nc-list) c-semi-lit-near-cache) 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." (widen) (c-trim-lit-pos-cache) (c-semi-trim-near-cache) - (setq c-lit-pos-cache-limit here) (save-match-data (let* ((pos-and-state (c-semi-get-near-cache-entry here)) (pos (car pos-and-state)) @@ -2849,9 +2848,8 @@ comment at the start of cc-engine.el for more info." ;; END is the end of the literal enclosing HERE, if any, or nil otherwise. (defun c-full-trim-near-cache () - ;; Remove stale entries in `c-full-lit-near-cache', i.e. those - ;; whose END entries, or positions, are above - ;; `c-state-full-nonlit-pos-cache-limit'. + ;; Remove stale entries in `c-full-lit-near-cache', i.e. those whose END + ;; entries, or positions, are above `c-full-near-cache-limit'. (let ((nc-list c-full-lit-near-cache) elt) (while nc-list (let ((elt (car nc-list))) @@ -2873,24 +2871,22 @@ comment at the start of cc-engine.el for more info." (let ((nc-pos-state (or (assq here c-full-lit-near-cache) (let ((nc-list c-full-lit-near-cache) - elt match (nc-pos 0) cand-pos-state) - (setq match - (catch 'found - (while nc-list - (setq elt (car nc-list)) - (when - (and (car (cddr elt)) - (>= here (nth 8 (cadr elt))) - (< here (car (cddr elt)))) - (throw 'found elt)) - (when - (and (< (car elt) here) - (> (car elt) nc-pos)) - (setq nc-pos (car elt) - cand-pos-state elt)) - (setq nc-list (cdr nc-list))) - nil)) - (or match cand-pos-state))))) + elt (nc-pos 0) cand-pos-state) + (catch 'found + (while nc-list + (setq elt (car nc-list)) + (when + (and (car (cddr elt)) + (>= here (nth 8 (cadr elt))) + (< here (car (cddr elt)))) + (throw 'found elt)) + (when + (and (< (car elt) here) + (> (car elt) nc-pos)) + (setq nc-pos (car elt) + cand-pos-state elt)) + (setq nc-list (cdr nc-list))) + cand-pos-state))))) ;; Move the found cache entry, if any, to the front of the list. (when (and nc-pos-state (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." (defsubst c-truncate-lit-pos-cache (pos) ;; Truncate the upper bound of each of the three caches to POS, if it is ;; higher than that position. - (setq c-lit-pos-cache-limit - (min c-lit-pos-cache-limit pos) - c-semi-near-cache-limit - (min c-semi-near-cache-limit pos) - c-full-near-cache-limit - (min c-full-near-cache-limit pos))) + (setq c-lit-pos-cache-limit (min c-lit-pos-cache-limit pos) + c-semi-near-cache-limit (min c-semi-near-cache-limit pos) + c-full-near-cache-limit (min c-full-near-cache-limit pos))) ;; A system for finding noteworthy parens before the point. @@ -4044,8 +4037,6 @@ comment at the start of cc-engine.el for more info." c-state-cache-good-pos 1 c-state-nonlit-pos-cache nil c-state-nonlit-pos-cache-limit 1 - c-lit-pos-cache nil - c-lit-pos-cache-limit 1 c-state-brace-pair-desert nil c-state-point-min 1 c-state-point-min-lit-type nil @@ -4320,8 +4311,6 @@ comment at the start of cc-engine.el for more info." c-state-cache-good-pos c-state-nonlit-pos-cache c-state-nonlit-pos-cache-limit - c-lit-pos-cache - c-lit-pos-cache-limit c-state-brace-pair-desert c-state-point-min 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." ;; doesn't work with filladapt but it's better than nothing. (set (make-local-variable 'fill-paragraph-function) 'c-fill-paragraph) + ;; Initialize the three literal sub-caches. + (c-truncate-lit-pos-cache 1) ;; Initialize the cache of brace pairs, and opening braces/brackets/parens. (c-state-cache-init) ;; Initialize the "brace stack" cache. -- 2.39.5