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/hist.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/hist.c') diff --git a/src/hist.c b/src/hist.c index 123ed7b..bff1325 100644 --- a/src/hist.c +++ b/src/hist.c @@ -67,8 +67,7 @@ static TERM_NOINLINE bool ring_grow(struct hist *h, uint64_t n) uint64_t cap = h->ring ? (uint64_t)h->ring_mask + 1 : 65536; if (cap < 65536) cap = 65536; - while (cap < h->head - h->tail + n) - cap *= 2; + cap = term_grow_cap64(cap, h->head - h->tail + n); struct hline *ring = term_aligned_alloc(64, (size_t)cap * sizeof(*ring)); if (!ring) return false; -- cgit v1.2.3