From ff9513f811b0d6f1d6ff258c1b8670a7701f2fa1 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Wed, 13 Aug 2025 00:09:35 +0200 Subject: piece-table: Add text_buffer_resize --- src/piece-table.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/piece-table.c') 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 @@ -71,6 +71,13 @@ text_buffer_init (text_buffer *tb) tb->contents = NULL; } +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) { @@ -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; } -- cgit v1.2.3