From 4741f7a6dfa144ce65cf3bbdd4a1bc6bee6df2e5 Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Tue, 13 Oct 2026 13:36:27 +0300 Subject: Optimize and simplify loops, table lookups, and branchless parsers - Replace sequential colon-counting loop with branchless CTZ bitmask in src/pen.h - Replace linear strchr with 256-bit ASCII punctuation bitmask in src/selection.c - Flatten 3D color cube loop and precompute constants in src/palette.c - Use static 256-byte LUT for hex decoding and bsearch for termcap in src/escape.c - Replace capacity doubling while loops with branchless CLZ pow2 helpers across core - Use direct memset/memcpy in src/snapshot.c - Optimize input digit/byte formatting, alt-prefix path, and make keyboard state optional in src/input.c --- src/screen.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/screen.c') diff --git a/src/screen.c b/src/screen.c index 681c42b..d6a408d 100644 --- a/src/screen.c +++ b/src/screen.c @@ -10,9 +10,7 @@ static void *grow(struct grow_buf *b, size_t bytes) { if (bytes > b->cap) { - size_t cap = b->cap ? b->cap : 256; - while (cap < bytes) - cap *= 2; + size_t cap = term_grow_cap(b->cap ? b->cap : 256, bytes); void *data = realloc(b->data, cap); if (!data) return NULL; -- cgit v1.2.3