diff options
author | Ian Lance Taylor <iant@golang.org> | 2020-10-24 14:47:44 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2020-10-27 13:58:02 -0700 |
commit | 668894d7b584b40ddb46e9e2e2ffa637f4d732e5 (patch) | |
tree | 6c97d325215c8462f375f142d1e91099cc4edb68 /libgo/go/bytes/bytes.go | |
parent | 2b3e722a3ca1b9dcfff1c016e651d0d681de1af0 (diff) | |
download | gcc-668894d7b584b40ddb46e9e2e2ffa637f4d732e5.zip gcc-668894d7b584b40ddb46e9e2e2ffa637f4d732e5.tar.gz gcc-668894d7b584b40ddb46e9e2e2ffa637f4d732e5.tar.bz2 |
libgo: update to Go 1.15.3 release
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/265717
Diffstat (limited to 'libgo/go/bytes/bytes.go')
-rw-r--r-- | libgo/go/bytes/bytes.go | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/libgo/go/bytes/bytes.go b/libgo/go/bytes/bytes.go index aa07b9f..ce52649f1 100644 --- a/libgo/go/bytes/bytes.go +++ b/libgo/go/bytes/bytes.go @@ -227,19 +227,26 @@ func IndexAny(s []byte, chars string) int { continue } r, width = utf8.DecodeRune(s[i:]) - if r == utf8.RuneError { - for _, r = range chars { - if r == utf8.RuneError { + if r != utf8.RuneError { + // r is 2 to 4 bytes + if len(chars) == width { + if chars == string(r) { return i } + continue + } + // Use bytealg.IndexString for performance if available. + if bytealg.MaxLen >= width { + if bytealg.IndexString(chars, string(r)) >= 0 { + return i + } + continue } - continue } - // r is 2 to 4 bytes. Using strings.Index is more reasonable, but as the bytes - // package should not import the strings package, use bytealg.IndexString - // instead. And this does not seem to lose much performance. - if chars == string(r) || bytealg.IndexString(chars, string(r)) >= 0 { - return i + for _, ch := range chars { + if r == ch { + return i + } } } return -1 @@ -304,19 +311,26 @@ func LastIndexAny(s []byte, chars string) int { } r, size := utf8.DecodeLastRune(s[:i]) i -= size - if r == utf8.RuneError { - for _, r = range chars { - if r == utf8.RuneError { + if r != utf8.RuneError { + // r is 2 to 4 bytes + if len(chars) == size { + if chars == string(r) { return i } + continue + } + // Use bytealg.IndexString for performance if available. + if bytealg.MaxLen >= size { + if bytealg.IndexString(chars, string(r)) >= 0 { + return i + } + continue } - continue } - // r is 2 to 4 bytes. Using strings.Index is more reasonable, but as the bytes - // package should not import the strings package, use bytealg.IndexString - // instead. And this does not seem to lose much performance. - if chars == string(r) || bytealg.IndexString(chars, string(r)) >= 0 { - return i + for _, ch := range chars { + if r == ch { + return i + } } } return -1 |