[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode a788ab2 209/385: more efficient layout ca
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode a788ab2 209/385: more efficient layout caching |
Date: |
Tue, 5 Oct 2021 23:59:33 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit a788ab23019619d3e8109dda5d42c59b7e16603d
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
more efficient layout caching
---
haskell-tng-layout.el | 138 +++++++++++++++++++++++++++-----------------------
1 file changed, 76 insertions(+), 62 deletions(-)
diff --git a/haskell-tng-layout.el b/haskell-tng-layout.el
index d5893e5..5f4995c 100644
--- a/haskell-tng-layout.el
+++ b/haskell-tng-layout.el
@@ -38,14 +38,28 @@
;; in a region.
(defvar-local haskell-tng--layout-cache nil)
-(defun haskell-tng--layout-cache-invalidation (_beg _end _pre-length)
+;; We only need to invalidate regions that are on or after the beginning of
user
+;; edits. But doing the pruning will slow down insertions. We store the
smallest
+;; point that the user edits to invalidate on access.
+(defvar-local haskell-tng--layout-cache-invalid nil)
+(defun haskell-tng--layout-cache-invalidation (beg _end _pre-length)
"For use in `after-change-functions' to invalidate the state of
the layout engine."
- ;; TODO we only need to invalidate regions that are on or after the _beg. But
- ;; doing so might slow down insertions. We could be smarter and store the
_beg
- ;; then prune when doing the cache retrieval.
- (when haskell-tng--layout-cache
- (setq haskell-tng--layout-cache nil)))
+ (setq
+ haskell-tng--layout-cache-invalid
+ (min beg (or haskell-tng--layout-cache-invalid
+ most-positive-fixnum))))
+
+(defun haskell-tng--layout-pruned-cache ()
+ (let ((beg haskell-tng--layout-cache-invalid))
+ (if beg
+ (setq
+ haskell-tng--layout-cache-invalid nil
+ haskell-tng--layout-cache
+ (seq-filter
+ (lambda (it) (<= (cdar it) beg))
+ haskell-tng--layout-cache))
+ haskell-tng--layout-cache)))
;; TODO a visual debugging option would be great, showing virtuals as overlays
@@ -86,8 +100,8 @@ using a cache if available."
(layout (or
(cdr (seq-find
(lambda (it) (and (< (caar it) (point))
- (<= (point) (cdar it))))
- haskell-tng--layout-cache))
+ (<= (point) (cdar it))))
+ (haskell-tng--layout-pruned-cache)))
(haskell-tng--layout-rebuild-cache-at-point)))
(unless (eq layout t) layout)))
@@ -98,62 +112,62 @@ using a cache if available."
(save-excursion
(forward-char -1)
(haskell-tng--layout-rebuild-cache-at-point))
- (let* ((min
- (save-excursion
- (end-of-line 1)
- (or (re-search-backward toplevel nil t) 0)))
- (max
- (save-excursion
- (end-of-line 1)
- (or (and (re-search-forward toplevel nil t)
- (match-beginning 0))
- (point-max))))
- (module
+ (let* ((min
+ (save-excursion
+ (end-of-line 1)
+ (or (re-search-backward toplevel nil t) 0)))
+ (max
+ (save-excursion
+ (end-of-line 1)
+ (or (and (re-search-forward toplevel nil t)
+ (match-beginning 0))
+ (point-max))))
+ (module
+ (save-excursion
+ (goto-char min)
+ (looking-at (rx word-start "module" word-end))))
+ (before-module
+ (save-excursion
+ (goto-char max)
+ (looking-at (rx word-start "module" word-end))))
+ case-fold-search
+ cache)
+
+ ;; `module ... where { ... }' special cases:
+ ;;
+ ;; 1. before module, nothing
+ ;; 2. after module, only an open
+ ;; 3. eob, extra close
+ ;; 4. everywhere else, extra sep
+ (when module
+ (push `(,max nil) cache))
+ (when (not (or module before-module))
+ (if (eq max (point-max))
+ (push `(nil ,max) cache)
+ (push `(nil nil ,max) cache))
(save-excursion
(goto-char min)
- (looking-at (rx word-start "module" word-end))))
- (before-module
- (save-excursion
- (goto-char max)
- (looking-at (rx word-start "module" word-end))))
- case-fold-search
- cache)
-
- ;; `module ... where { ... }' special cases:
- ;;
- ;; 1. before module, nothing
- ;; 2. after module, only an open
- ;; 3. eob, extra close
- ;; 4. everywhere else, extra sep
- (when module
- (push `(,max nil) cache))
- (when (not (or module before-module))
- (if (eq max (point-max))
- (push `(nil ,max) cache)
- (push `(nil nil ,max) cache))
- (save-excursion
- (goto-char min)
- (while (< (point) max)
- (when-let (wldo (haskell-tng--layout-next-wldo max))
- (push wldo cache)))))
-
- ;; TODO remove this sanity check when we are happy
- ;; a sanity check that all points are within the bounds
- (cl-flet ((good (type p)
- (when (and p (or (<= p min) (< max p)))
- (message "BUG: LAYOUT %S at %S" type p))))
- (dolist (block cache)
- (pcase block
- (`(,open . (,close . ,seps))
- (good 'OPEN open)
- (good 'CLOSE close)
- (dolist (sep seps)
- (good 'SEP sep))))))
-
- (let ((key (cons min max))
- (value (or (reverse cache) t)))
- (push (cons key value) haskell-tng--layout-cache)
- value)))))
+ (while (< (point) max)
+ (when-let (wldo (haskell-tng--layout-next-wldo max))
+ (push wldo cache)))))
+
+ ;; TODO remove this sanity check when we are happy
+ ;; a sanity check that all points are within the bounds
+ (cl-flet ((good (type p)
+ (when (and p (or (<= p min) (< max p)))
+ (message "BUG: LAYOUT %S at %S" type p))))
+ (dolist (block cache)
+ (pcase block
+ (`(,open . (,close . ,seps))
+ (good 'OPEN open)
+ (good 'CLOSE close)
+ (dolist (sep seps)
+ (good 'SEP sep))))))
+
+ (let ((key (cons min max))
+ (value (or (reverse cache) t)))
+ (push (cons key value) haskell-tng--layout-cache)
+ value)))))
(defun haskell-tng--layout-next-wldo (limit)
(catch 'wldo
- [nongnu] elpa/haskell-tng-mode 4cbf702 205/385: move third party deps to -contrib, (continued)
- [nongnu] elpa/haskell-tng-mode 4cbf702 205/385: move third party deps to -contrib, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3ff278e 227/385: ability to not continue comments, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode dbcef71 235/385: workaround the env file situation, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5892c04 232/385: small things, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 44dc467 248/385: notes on motivation, contributing and collaboration, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6f2b5ee 266/385: font lock CPP, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fdbd0a2 239/385: updates for hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b2e2c3a 293/385: stop stack from being an asshole, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ee07f6d 172/385: type indentation tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 59354b6 198/385: support hanging type alignment, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a788ab2 209/385: more efficient layout caching,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode f7e8040 213/385: = ends a type sig, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fe9d65d 222/385: helper for yatemplates, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bc93c3d 224/385: very alpha hsinspect support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 658ddb6 251/385: docs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 73a60f5 309/385: cache `which hsinspect` per project, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5707166 365/385: use new ghcflags-provided PATH, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b1c664b 364/385: allow hsinspect population in the background, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ce17d96 376/385: new hsinspect release, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode eb6b487 357/385: test fqn-at-point and fix a longstanding bug, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 103e758 325/385: expose some more hsinspect-0.0.8 index info, ELPA Syncer, 2021/10/06