summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2024-01-12 23:03:24 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2024-01-18 22:48:52 +0100
commit81dd326da683f53cecee75b907f55dbd1b5d5460 (patch)
tree134261ee40f461d96833aa92447c19256b647119
parent49f7232b4c580197413528e03b699ca519905fdc (diff)
par: piece-table: useful comments
-rw-r--r--par/piece-table.scm8
1 files changed, 7 insertions, 1 deletions
diff --git a/par/piece-table.scm b/par/piece-table.scm
index c638a2d..6b3985b 100644
--- a/par/piece-table.scm
+++ b/par/piece-table.scm
@@ -113,7 +113,7 @@
;; The piece table itself;
;; original is a ro-buffer, add is an add-buffer (a string designed to grow)
-;; and pieces is a list of pieces
+;; and pieces is a list of pieces (should we avoid allocations?)
(define-record-type <piece-table>
(%make-piece-table original-buffer add-buffer pieces)
piece-table?
@@ -129,6 +129,7 @@
(list (make-piece ro-buffer 0 (string-length original) 'normal)))))
(define (piece-table-index piece-table pos)
+ ;; TODO: Validate input
(let loop ((pieces (piece-table-pieces piece-table))
(start 0))
(let* ((piece (car pieces))
@@ -158,6 +159,10 @@
(values (take l i) (list-ref l i) (drop l (+ 1 i)))))
(define (piece-table-insert! piece-table pos str type)
+ ;; TODO: validate input
+ ;; TODO: Try to reuse the caracters on the target buffer if they are already
+ ;; there? Is this maximum evilness? => it's just a string-ref and it prevents
+ ;; us from creating pieces!
(define candidate ((add-buffer-append!
(piece-table-add-buffer piece-table) str)
type))
@@ -182,6 +187,7 @@
; - That would need other way to find the affected pieces and manipulate them.
; > we'll leave it for the future
(define (piece-table-delete! piece-table from len)
+ ;; TODO: Validate input
(let*-values (((idx rem) (piece-table-text-pos->piece-idx+remainder
piece-table from)) ; TODO because of the <=
((end-idx end-rem) (piece-table-text-pos->piece-idx+remainder