improve strings.index_multi

There's no point searching for substrings after lowest_index,
so let's not.

This significantly improves performance on long strings.
This commit is contained in:
Adam Zadrożny
2024-12-04 14:29:49 +01:00
parent c79466ab3c
commit 5dfc24882f
2 changed files with 21 additions and 1 deletions
+2 -1
View File
@@ -1872,7 +1872,8 @@ index_multi :: proc(s: string, substrs: []string) -> (idx: int, width: int) {
lowest_index := len(s)
found := false
for substr in substrs {
if i := index(s, substr); i >= 0 {
haystack := s[:min(len(s), lowest_index + len(substr))]
if i := index(haystack, substr); i >= 0 {
if i < lowest_index {
lowest_index = i
width = len(substr)