mirror of
https://github.com/odin-lang/Odin.git
synced 2026-08-14 09:44:26 +00:00
Merge pull request #7255 from mororo18/perf/bytes-index-any-bitset
core/bytes: optimize `index_any` with a byte bitset
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user