Commit 9dee49ed authored by Alan Mackenzie's avatar Alan Mackenzie

Tidy up the literal cacheing in CC Mode, optimizing c-full-pp-to-literal

(Intermediate commit)

* lisp/progmodes/cc-engine.el, lisp/progmodes/cc-fonts.el
* lisp/progmodes/cc-mode.el : Rename:
c-state-semi-nonlit-pos-cache -> c-lit-pos-cache,
c-state-semi-nonlit-pos-cache-limit -> c-lit-pos-cache-limit,
c-state-semi-nonlit-near-cache -> c-semi-lit-near-cache,
c-truncate-semi-nonlit-pos-cache -> c-truncate-lit-pos-cache,
c-state-semi-trim-near-cache -> c-semi-trim-near-cache,
c-state-semi-get-near-cache-entry -> c-semi-get-near-cache-entry,
c-state-semi-put-near-cache-entry -> c-semi-put-near-cache-entry,
c-state-semi-pp-to-literal -> c-semi-pp-to-literal,
c-state-full-pp-to-literal -> c-full-pp-to-literal,
c-state-semi-trim-cache -> c-trim-lit-pos-cache.

* lisp/progmodes/cc-engine.el (c-semi-near-cache-limit): New variable.
(c-truncate-lit-pos-cache): This now truncates the cache variables for all
three lit- sub-caches.
(c-semi-put-near-cache-entry): Increase c-semi-near-cache-limit to the
position of the new entry.
(c-full-near-cache-limit, c-full-lit-near-cache): New variables.
(c-full-trim-near-cache, c-full-get-near-cache-entry)
(c-full-put-near-cache-entry): New functions.
(c-full-pp-to-literal): Amend to use the new functions, and to optimize the
use of the available caches, similarly to c-semi-pp-to-literal.
parent 56964f3d
This diff is collapsed.
...@@ -1681,7 +1681,7 @@ casts and declarations are fontified. Used on level 2 and higher." ...@@ -1681,7 +1681,7 @@ casts and declarations are fontified. Used on level 2 and higher."
;; font-lock-keyword-face. It always returns NIL to inhibit this and ;; font-lock-keyword-face. It always returns NIL to inhibit this and
;; prevent a repeat invocation. See elisp/lispref page "Search-based ;; prevent a repeat invocation. See elisp/lispref page "Search-based
;; Fontification". ;; Fontification".
(let* ((state (c-state-semi-pp-to-literal (point))) (let* ((state (c-semi-pp-to-literal (point)))
(string-start (and (eq (cadr state) 'string) (string-start (and (eq (cadr state) 'string)
(car (cddr state)))) (car (cddr state))))
(raw-id (and string-start (raw-id (and string-start
......
...@@ -1219,7 +1219,7 @@ Note that the style variables are always made local to the buffer." ...@@ -1219,7 +1219,7 @@ Note that the style variables are always made local to the buffer."
(point-max) t t) (point-max) t t)
(progn (progn
(c-clear-char-property (1- (point)) 'syntax-table) (c-clear-char-property (1- (point)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1- (point))) (c-truncate-lit-pos-cache (1- (point)))
(not (memq (char-before) c-string-delims))))) (not (memq (char-before) c-string-delims)))))
(memq (char-before) c-string-delims)) (memq (char-before) c-string-delims))
(progn (progn
...@@ -1257,14 +1257,14 @@ Note that the style variables are always made local to the buffer." ...@@ -1257,14 +1257,14 @@ Note that the style variables are always made local to the buffer."
(backward-sexp) (backward-sexp)
(c-clear-char-property eoll-1 'syntax-table) (c-clear-char-property eoll-1 'syntax-table)
(c-clear-char-property (point) 'syntax-table) (c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point))) (c-truncate-lit-pos-cache (point)))
;; Opening " at EOB. ;; Opening " at EOB.
(c-clear-char-property (1- (point)) 'syntax-table)) (c-clear-char-property (1- (point)) 'syntax-table))
(when (and (c-search-backward-char-property 'syntax-table '(15) c-new-BEG) (when (and (c-search-backward-char-property 'syntax-table '(15) c-new-BEG)
(memq (char-after) c-string-delims)) ; Ignore an unterminated raw string's (. (memq (char-after) c-string-delims)) ; Ignore an unterminated raw string's (.
;; Opening " on last line of text (without EOL). ;; Opening " on last line of text (without EOL).
(c-clear-char-property (point) 'syntax-table) (c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point)) (c-truncate-lit-pos-cache (point))
(setq c-new-BEG (min c-new-BEG (point)))))) (setq c-new-BEG (min c-new-BEG (point))))))
(t (goto-char end) ; point-max (t (goto-char end) ; point-max
...@@ -1273,7 +1273,7 @@ Note that the style variables are always made local to the buffer." ...@@ -1273,7 +1273,7 @@ Note that the style variables are always made local to the buffer."
(c-search-backward-char-property 'syntax-table '(15) c-new-BEG) (c-search-backward-char-property 'syntax-table '(15) c-new-BEG)
(memq (char-after) c-string-delims)) (memq (char-after) c-string-delims))
(c-clear-char-property (point) 'syntax-table) (c-clear-char-property (point) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (point))))) (c-truncate-lit-pos-cache (point)))))
(unless (unless
(or (and (or (and
...@@ -1285,13 +1285,13 @@ Note that the style variables are always made local to the buffer." ...@@ -1285,13 +1285,13 @@ Note that the style variables are always made local to the buffer."
(when (and (eq end-literal-type 'string) (when (and (eq end-literal-type 'string)
(not (eq (char-before (cdr end-limits)) ?\())) (not (eq (char-before (cdr end-limits)) ?\()))
(c-clear-char-property (1- (cdr end-limits)) 'syntax-table) (c-clear-char-property (1- (cdr end-limits)) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (1- (cdr end-limits))) (c-truncate-lit-pos-cache (1- (cdr end-limits)))
(setq c-new-END (max c-new-END (cdr end-limits)))) (setq c-new-END (max c-new-END (cdr end-limits))))
(when (and (eq beg-literal-type 'string) (when (and (eq beg-literal-type 'string)
(memq (char-after (car beg-limits)) c-string-delims)) (memq (char-after (car beg-limits)) c-string-delims))
(c-clear-char-property (car beg-limits) 'syntax-table) (c-clear-char-property (car beg-limits) 'syntax-table)
(c-truncate-semi-nonlit-pos-cache (car beg-limits)) (c-truncate-lit-pos-cache (car beg-limits))
(setq c-new-BEG (min c-new-BEG (car beg-limits))))))) (setq c-new-BEG (min c-new-BEG (car beg-limits)))))))
(defun c-after-change-mark-abnormal-strings (beg end _old-len) (defun c-after-change-mark-abnormal-strings (beg end _old-len)
...@@ -1587,7 +1587,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") ...@@ -1587,7 +1587,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(when (c-search-forward-char-property-with-value-on-char (when (c-search-forward-char-property-with-value-on-char
'syntax-table '(1) ?\' c-new-END) 'syntax-table '(1) ?\' c-new-END)
(c-invalidate-state-cache (1- (point))) (c-invalidate-state-cache (1- (point)))
(c-truncate-semi-nonlit-pos-cache (1- (point))) (c-truncate-lit-pos-cache (1- (point)))
(c-clear-char-property-with-value-on-char (c-clear-char-property-with-value-on-char
(1- (point)) c-new-END (1- (point)) c-new-END
'syntax-table '(1) 'syntax-table '(1)
...@@ -1623,7 +1623,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") ...@@ -1623,7 +1623,7 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(setq num-beg (match-beginning 0) (setq num-beg (match-beginning 0)
num-end (match-end 0)) num-end (match-end 0))
(c-invalidate-state-cache num-beg) (c-invalidate-state-cache num-beg)
(c-truncate-semi-nonlit-pos-cache num-beg) (c-truncate-lit-pos-cache num-beg)
(c-put-char-properties-on-char num-beg num-end (c-put-char-properties-on-char num-beg num-end
'syntax-table '(1) ?') 'syntax-table '(1) ?')
(c-put-char-properties-on-char num-beg num-end (c-put-char-properties-on-char num-beg num-end
...@@ -1635,13 +1635,13 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".") ...@@ -1635,13 +1635,13 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(goto-char (match-end 0))) (goto-char (match-end 0)))
((looking-at "\\\\'") ; Anomalous construct. ((looking-at "\\\\'") ; Anomalous construct.
(c-invalidate-state-cache (1- (point))) (c-invalidate-state-cache (1- (point)))
(c-truncate-semi-nonlit-pos-cache (1- (point))) (c-truncate-lit-pos-cache (1- (point)))
(c-put-char-properties-on-char (1- (point)) (+ (point) 2) (c-put-char-properties-on-char (1- (point)) (+ (point) 2)
'syntax-table '(1) ?') 'syntax-table '(1) ?')
(goto-char (match-end 0))) (goto-char (match-end 0)))
(t (t
(c-invalidate-state-cache (1- (point))) (c-invalidate-state-cache (1- (point)))
(c-truncate-semi-nonlit-pos-cache (1- (point))) (c-truncate-lit-pos-cache (1- (point)))
(c-put-char-property (1- (point)) 'syntax-table '(1)))) (c-put-char-property (1- (point)) 'syntax-table '(1))))
;; Prevent the next `c-quoted-number-straddling-point' getting ;; Prevent the next `c-quoted-number-straddling-point' getting
;; confused by already processed single quotes. ;; confused by already processed single quotes.
......
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