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/selection.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/selection.c') diff --git a/src/selection.c b/src/selection.c index 6f7336f..0eda34f 100644 --- a/src/selection.c +++ b/src/selection.c @@ -38,7 +38,15 @@ static char *link_at_text(const struct term *t, struct term_vector2i cell) char *out = NULL; if (url && col >= start + (int)(url - text)) { size_t n = strlen(url); - while (n && strchr(".,;:!?)]}>\"'", url[n - 1])) url[--n] = 0; + /* Bitmask matching trailing punctuation characters: .,;:!?)]}>"' */ + static const uint64_t mask[4] = { + 0xCC00528600000000ULL, + 0x2000000020000000ULL, + 0ULL, + 0ULL + }; + while (n && (mask[(unsigned char)url[n - 1] >> 6] & (1ULL << ((unsigned char)url[n - 1] & 63)))) + url[--n] = 0; if (col < start + (int)(url - text) + (int)n && n > scheme) out = term_strdup(url); } -- cgit v1.2.3