aboutsummaryrefslogtreecommitdiff
path: root/src/bytes
diff options
context:
space:
mode:
authorAndy Pan <panjf2000@gmail.com>2020-03-23 02:51:26 +0000
committerIan Lance Taylor <iant@golang.org>2020-03-23 03:44:45 +0000
commit1250a324b405c0a8f6eb4751b8471dd0ae7cb7bc (patch)
tree6e121c814b8ecad678fb8ceeb2d44cf7efe19746 /src/bytes
parentab2cc45cc9a094bb29d7adc3191dd6ee2080af83 (diff)
downloadgo-1250a324b405c0a8f6eb4751b8471dd0ae7cb7bc.tar.gz
go-1250a324b405c0a8f6eb4751b8471dd0ae7cb7bc.zip
bytes: narrow the search of IndexByte in Index
Change-Id: I5a47b18b64e7f781dcc77440b06de36966e3d01d GitHub-Last-Rev: 8576f1931d6e87a0823632ee35fcbc0d4eaaeaaf GitHub-Pull-Request: golang/go#37993 Reviewed-on: https://go-review.googlesource.com/c/go/+/224589 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/bytes')
-rw-r--r--src/bytes/bytes.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go
index ef7294d805..0dce6af226 100644
--- a/src/bytes/bytes.go
+++ b/src/bytes/bytes.go
@@ -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
@@ -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