Skip to content

Commit

Permalink
bytes: narrow the search of IndexByte in Index
Browse files Browse the repository at this point in the history
Change-Id: I5a47b18b64e7f781dcc77440b06de36966e3d01d
GitHub-Last-Rev: 8576f19
GitHub-Pull-Request: #37993
Reviewed-on: https://go-review.googlesource.com/c/go/+/224589
Reviewed-by: Ian Lance Taylor <iant@golang.org>
  • Loading branch information
panjf2000 authored and ianlancetaylor committed Mar 23, 2020
1 parent ab2cc45 commit 1250a32
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/bytes/bytes.go
Expand Up @@ -1100,11 +1100,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 @@ -1129,11 +1129,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 1250a32

Please sign in to comment.