diff options
| author | Adam Zadrożny <zadroznyadam@protonmail.com> | 2024-12-04 14:29:49 +0100 |
|---|---|---|
| committer | Adam Zadrożny <zadroznyadam@protonmail.com> | 2024-12-04 14:29:49 +0100 |
| commit | 5dfc24882fb9ed40c79e60963dbfdbccd3c82450 (patch) | |
| tree | 55f5a9607a1e3b2939d470d3879cb82198932cc2 /core/strings/strings.odin | |
| parent | c79466ab3cdc95d436752d37370336423c749211 (diff) | |
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.
Diffstat (limited to 'core/strings/strings.odin')
| -rw-r--r-- | core/strings/strings.odin | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/core/strings/strings.odin b/core/strings/strings.odin index af93ff33c..c014d2b2b 100644 --- a/core/strings/strings.odin +++ b/core/strings/strings.odin @@ -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) |