1
0
mirror of https://github.com/golang/go synced 2024-09-29 13:24:28 -06:00

strings: narrow the search range of IndexByte in Index

This commit is contained in:
Andy Pan 2020-03-23 12:23:31 +08:00
parent 4d5bb9c609
commit 81c13c0f5b

View File

@ -1053,11 +1053,11 @@ func Index(s, substr string) int {
if s[i] != c0 {
// IndexByte is faster than bytealg.IndexString, so use it as long as
// we're not getting lots of false positives.
o := IndexByte(s[i:t], c0)
o := IndexByte(s[i+1:t], c0)
if o < 0 {
return -1
}
i += o
i += o + 1
}
if s[i+1] == c1 && s[i:i+n] == substr {
return i
@ -1082,11 +1082,11 @@ func Index(s, substr string) int {
fails := 0
for i < t {
if s[i] != c0 {
o := IndexByte(s[i:t], c0)
o := IndexByte(s[i+1:t], c0)
if o < 0 {
return -1
}
i += o
i += o + 1
}
if s[i+1] == c1 && s[i:i+n] == substr {
return i