Skip to content

Commit 1250a32

Browse files
panjf2000ianlancetaylor
authored andcommitted
bytes: narrow the search of IndexByte in Index
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>
1 parent ab2cc45 commit 1250a32

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/bytes/bytes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,11 +1100,11 @@ func Index(s, sep []byte) int {
11001100
if s[i] != c0 {
11011101
// IndexByte is faster than bytealg.Index, so use it as long as
11021102
// we're not getting lots of false positives.
1103-
o := IndexByte(s[i:t], c0)
1103+
o := IndexByte(s[i+1:t], c0)
11041104
if o < 0 {
11051105
return -1
11061106
}
1107-
i += o
1107+
i += o + 1
11081108
}
11091109
if s[i+1] == c1 && Equal(s[i:i+n], sep) {
11101110
return i
@@ -1129,11 +1129,11 @@ func Index(s, sep []byte) int {
11291129
t := len(s) - n + 1
11301130
for i < t {
11311131
if s[i] != c0 {
1132-
o := IndexByte(s[i:t], c0)
1132+
o := IndexByte(s[i+1:t], c0)
11331133
if o < 0 {
11341134
break
11351135
}
1136-
i += o
1136+
i += o + 1
11371137
}
11381138
if s[i+1] == c1 && Equal(s[i:i+n], sep) {
11391139
return i

0 commit comments

Comments
 (0)