From 11c9d6a3dd89f68c12af5d782e859791703fe999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Victor=20Moror=C3=B3?= Date: Sat, 8 Aug 2026 11:05:20 -0300 Subject: [PATCH] core/bytes: optimize index_any with a byte bitset --- core/bytes/bytes.odin | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/core/bytes/bytes.odin b/core/bytes/bytes.odin index 55eca5386..36d2be4d4 100644 --- a/core/bytes/bytes.odin +++ b/core/bytes/bytes.odin @@ -709,13 +709,20 @@ index_any :: proc(s, chars: []byte) -> int { if chars == nil { return -1 } + if len(chars) == 1 { + return index_byte(s, chars[0]) + } + + // NOTE: Same technique as strings.Ascii_Set, duplicated here since + // core:strings imports core:bytes and not the other way around. + set: [8]u32 + for c in chars { + set[c >> 5] |= 1 << (u32(c) & 31) + } - // TODO(bill): Optimize for r, i in s { - for c in chars { - if r == c { - return i - } + if set[r >> 5] & (1 << (u32(r) & 31)) != 0 { + return i } } return -1