From 8576f1931d6e87a0823632ee35fcbc0d4eaaeaaf Mon Sep 17 00:00:00 2001 From: Andy Pan Date: Sun, 22 Mar 2020 10:51:21 +0800 Subject: [PATCH] bytes: narrow the search of IndexByte in Index --- src/bytes/bytes.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index e872cc20506..8189293beea 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -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 @@ -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