diff options
author | Andy Pan <panjf2000@gmail.com> | 2020-03-23 04:53:40 +0000 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-03-23 19:14:29 +0000 |
commit | 6aded2524cb77eeab907e64512c5f7c54b530756 (patch) | |
tree | 2c7627ee6ff8387385dc56dce0ead7b090dc2420 /src/strings | |
parent | 3adbdb6d9931276894c5e2524f5ca8ca26bfeab5 (diff) | |
download | go-6aded2524cb77eeab907e64512c5f7c54b530756.tar.gz go-6aded2524cb77eeab907e64512c5f7c54b530756.zip |
strings: narrow the search range of IndexByte in Index
Same as https://golang.org/cl/224589.
Change-Id: I6a9e2ea60bf6e1888a95bad0331c92079a7eff99
GitHub-Last-Rev: 81c13c0f5b2ee6ae7842a7b73799b7821f78be59
GitHub-Pull-Request: golang/go#38016
Reviewed-on: https://go-review.googlesource.com/c/go/+/224593
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/strings')
-rw-r--r-- | src/strings/strings.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/strings/strings.go b/src/strings/strings.go index 2789f5fb25..6d78b9ef16 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -1044,11 +1044,11 @@ func Index(s, substr string) int { if s[i] != c0 { // IndexByte is faster than bytealg.IndexString, 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 && s[i:i+n] == substr { return i @@ -1073,11 +1073,11 @@ func Index(s, substr string) int { fails := 0 for i < t { if s[i] != c0 { - 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 && s[i:i+n] == substr { return i |