Skip to content

Commit

Permalink
bytes: narrow the search of IndexByte in Index
Browse files Browse the repository at this point in the history
  • Loading branch information
panjf2000 committed Mar 22, 2020
1 parent 4d5bb9c commit 8576f19
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bytes/bytes.go
Expand Up @@ -1019,11 +1019,11 @@ func Index(s, sep []byte) int {
if s[i] != c0 {
// IndexByte is faster than bytealg.Index, 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 && Equal(s[i:i+n], sep) {
return i
Expand All @@ -1048,11 +1048,11 @@ func Index(s, sep []byte) int {
t := len(s) - n + 1
for i < t {
if s[i] != c0 {
o := IndexByte(s[i:t], c0)
o := IndexByte(s[i+1:t], c0)
if o < 0 {
break
}
i += o
i += o + 1
}
if s[i+1] == c1 && Equal(s[i:i+n], sep) {
return i
Expand Down

0 comments on commit 8576f19

Please sign in to comment.