summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-01-25 02:10:21 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-01-25 02:10:21 +0100
commit92e82c76b97254a4fb70f09f45192b163962febb (patch)
tree6161d2df8cde30e5c6576c4e4c0939725db467ef
parente81dabefce9b0337c073514060a352e49a709440 (diff)
par: piece-table: simplify piece-table-index->piece+index
-rw-r--r--par/piece-table.scm7
1 files changed, 4 insertions, 3 deletions
diff --git a/par/piece-table.scm b/par/piece-table.scm
index 1707e7e..65e733f 100644
--- a/par/piece-table.scm
+++ b/par/piece-table.scm
@@ -192,6 +192,8 @@
(define (piece-table-for-each piece-table f from to)
;; TODO: default from and to
+ ;; TODO: maybe combine with the `piece-table-index->piece+index` to find the
+ ;; `from`
"Calls `f` through the characters of the piece-table, like `string-for-each`
would do, but the `f` call also includes the piece (to expose extra data) and
the index of the character"
@@ -236,8 +238,7 @@
(define (piece-table-index->piece+index piece-table pos)
"Returns (values piece remainder) or eof-object"
- (let loop ((idx 0)
- (piece (piece-table-piece piece-table))
+ (let loop ((piece (piece-table-piece piece-table))
(rem pos))
(let ((len (piece-length piece)))
(cond
@@ -247,7 +248,7 @@
;; TODO: No more pieces, return the end or eof?
(error "Requested position out of piece-table"))
(else
- (loop (+ idx 1) (piece-next piece) (- rem len)))))))
+ (loop (piece-next piece) (- rem len)))))))
(define (piece-table-piece-index piece-table i)
(let ((piece-prev/next (if (< i 0) piece-prev piece-next))