mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-13 01:21:38 -07:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user