summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2025-08-13 00:09:35 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2025-08-13 00:09:35 +0200
commitff9513f811b0d6f1d6ff258c1b8670a7701f2fa1 (patch)
tree060ed05418d5bdf88112cf8c94773907860ec878
parentaa15552d5784ca0da83d70995f268f30db11c916 (diff)
piece-table: Add text_buffer_resize
-rw-r--r--src/piece-table.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/piece-table.c b/src/piece-table.c
index 53a9088..21dbb1b 100644
--- a/src/piece-table.c
+++ b/src/piece-table.c
@@ -72,6 +72,13 @@ text_buffer_init (text_buffer *tb)
}
void
+text_buffer_resize (text_buffer *tb, size_t size)
+{
+ tb->size = size;
+ tb->contents = realloc (tb->contents, sizeof (*tb->contents) * size);
+}
+
+void
text_buffer_append (text_buffer *tb, char c)
{
size_t base_size = 1024;
@@ -81,10 +88,7 @@ text_buffer_append (text_buffer *tb, char c)
tb->size = base_size;
}
else if (tb->size == tb->used)
- {
- tb->contents = realloc (tb->contents,
- sizeof (*tb->contents) * tb->used*2);
- }
+ text_buffer_resize (tb, tb->size * 2);
tb->contents[tb->used++] = c;
}