[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rainbow-delimiters 3dfd3fa9b1 054/188: Use sorted-list cac
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rainbow-delimiters 3dfd3fa9b1 054/188: Use sorted-list caching to improve large-file performance |
Date: |
Sat, 1 Jan 2022 00:58:52 -0500 (EST) |
branch: elpa/rainbow-delimiters
commit 3dfd3fa9b11a81e62fca0443c2e1af28e42a4ce6
Author: Fanael Linithien <fanael4@gmail.com>
Commit: Steve Purcell <steve@sanityinc.com>
Use sorted-list caching to improve large-file performance
Fixes #29
---
rainbow-delimiters.el | 48 ++++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/rainbow-delimiters.el b/rainbow-delimiters.el
index 2e45225386..95a2ee7eaa 100644
--- a/rainbow-delimiters.el
+++ b/rainbow-delimiters.el
@@ -323,22 +323,34 @@ For example: 'rainbow-delimiters-depth-1-face'."
;; we build a simple cache around it. This brings the speed to around
;; what it used to be, while fixing the bug. See issue #25.
-;; TODO: maybe make the cache a little smarter than just caching the
-;; last call?
-
(defvar rainbow-delimiters-parse-partial-sexp-cache nil
"Cache of the last `parse-partial-sexp' call.
-If it's nil, there's nothing in the cache. Otherwise, it's a cons
-cell, where car is the position for which `parse-partial-sexp' was
-called and cdr is the result of the call.")
+It's a list of conses, where car is the position for which `parse-partial-sexp'
+was called and cdr is the result of the call. The list is ordered descending by
+car.")
(make-variable-buffer-local 'rainbow-delimiters-parse-partial-sexp-cache)
+(defconst rainbow-delimiters-parse-partial-sexp-cache-max-span 20000)
+
(defun rainbow-delimiters-syntax-ppss-flush-cache (beg _end)
"Flush the `parse-partial-sexp' cache starting at position BEG."
- (when (and rainbow-delimiters-parse-partial-sexp-cache
- (<= beg (car rainbow-delimiters-parse-partial-sexp-cache)))
- (setq rainbow-delimiters-parse-partial-sexp-cache nil)))
+ (let ((it rainbow-delimiters-parse-partial-sexp-cache))
+ (while (and it (>= (caar it) beg))
+ (setq it (cdr it)))
+ (setq rainbow-delimiters-parse-partial-sexp-cache it)))
+
+(defsubst rainbow-delimiters-syntax-ppss-run (from to oldstate
cache-nearest-after)
+ (while (< from to)
+ (let ((newpos (min to (+ from
rainbow-delimiters-parse-partial-sexp-cache-max-span))))
+ (let ((state (parse-partial-sexp from newpos nil nil oldstate)))
+ (if (/= newpos to)
+ (if cache-nearest-after
+ (push (cons newpos state) (cdr cache-nearest-after))
+ (push (cons newpos state)
rainbow-delimiters-parse-partial-sexp-cache)))
+ (setq oldstate state
+ from newpos))))
+ oldstate)
(defsubst rainbow-delimiters-syntax-ppss (pos)
"Parse-Partial-Sexp State at POS, defaulting to point.
@@ -350,12 +362,16 @@ upon.
This is essentialy `syntax-ppss', only specific to rainbow-delimiters
to work around a bug."
(save-excursion
- (let* ((cache rainbow-delimiters-parse-partial-sexp-cache)
- (ppss (if (and cache (>= pos (car cache)))
- (parse-partial-sexp (car cache) pos nil nil (cdr cache))
- (parse-partial-sexp (point-min) pos))))
- (setq rainbow-delimiters-parse-partial-sexp-cache (cons pos ppss))
- ppss)))
+ (let ((it rainbow-delimiters-parse-partial-sexp-cache)
+ (prev nil))
+ (while (and it (>= (caar it) pos))
+ (setq prev it)
+ (setq it (cdr it)))
+ (let* ((nearest-after (if (consp prev) prev nil))
+ (nearest-before (if (consp it) (car it) it))
+ (nearest-before-pos (if nearest-before (car nearest-before)
(point-min)))
+ (nearest-before-data (if nearest-before (cdr nearest-before)
nil)))
+ (rainbow-delimiters-syntax-ppss-run nearest-before-pos pos
nearest-before-data nearest-after)))))
;;; Nesting level
@@ -480,7 +496,7 @@ Returns t if char at loc meets one of the following
conditions:
- Inside a string.
- Inside a comment.
- Is an escaped char, e.g. ?\)"
- (let ((parse-state (rainbow-delimiters-syntax-ppss loc)))
+ (let ((parse-state (syntax-ppss loc)))
(or
(nth 3 parse-state) ; inside string?
(nth 4 parse-state) ; inside comment?
- [nongnu] elpa/rainbow-delimiters 7b882c9489 138/188: Merge (let … (let* …)) => (let* …)., (continued)
- [nongnu] elpa/rainbow-delimiters 7b882c9489 138/188: Merge (let … (let* …)) => (let* …)., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f57067cda5 140/188: Make Emacs 23 tests less verbose., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 6e9e17e739 008/188: Add a 'global-rainbow-delimiters-mode' for enabling rainbow-delimiters in all buffers., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters daa1737a8f 011/188: Whitespace changes., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f1ff54da71 051/188: Release version 1.3.5., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 2561e9853c 052/188: Attempt to fix issue #25., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 4c94853583 007/188: Add an item to the TODO list., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b9252e33d2 057/188: Remove unneeded require., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters b656f8c9cd 064/188: Wrap rainbow-delimiters-{un, }propertize-region with with-silent-modifications and with-syntax-table., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters a1dd352c1a 059/188: Fix docstring style errors reported by checkdoc., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 3dfd3fa9b1 054/188: Use sorted-list caching to improve large-file performance,
ELPA Syncer <=
- [nongnu] elpa/rainbow-delimiters fc70c7ec67 058/188: Use standard form of the footer comment., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 949078cfd7 042/188: Ignoring compiled files, ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters ee4519d20a 046/188: Use face symbols instead of face strings to better cooperate with htmlize., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 36df2e014c 067/188: Add code to highlight mismatched closing delimiters., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters c4c127992a 071/188: Use font-lock instead of jit-lock., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 4144a75120 070/188: Add lisp-interaction-mode to rainbow-delimiters-escaped-char-predicate-list., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 447293003b 069/188: Highlight correctly even in presence of these evil 'intangible' properties., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters f73763583c 077/188: Remove unneeded save-excursion., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters edf59bad7f 165/188: Move the usage instructions from installation to commentary., ELPA Syncer, 2022/01/01
- [nongnu] elpa/rainbow-delimiters 352b4f2bfe 177/188: No need to set inhibit-point-motion-hooks, ELPA Syncer, 2022/01/01