aboutsummaryrefslogtreecommitdiff
path: root/src/pkg/bytes/bytes.go
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2013-02-07 16:00:06 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2013-02-07 16:00:06 -0800
commit30a9957aacb21fef5195a43dba99669465a789e7 (patch)
tree87acc5cdf127b2977402111ec22a9b8b9ff296e2 /src/pkg/bytes/bytes.go
parent7594440ef134ddebc2864d207815eb325adda13f (diff)
downloadgo-30a9957aacb21fef5195a43dba99669465a789e7.tar.xz
bytes: minor optimization to lastIndexFunc
Before and after: BenchmarkTrimSpace 20000000 81.3 ns/op BenchmarkTrimSpace 50000000 58.0 ns/op (most whitespace trimming is ASCII whitespace) Same optimization appeared a handful of other places in this file, but not here. R=golang-dev, dave CC=golang-dev https://golang.org/cl/7305063
Diffstat (limited to 'src/pkg/bytes/bytes.go')
-rw-r--r--src/pkg/bytes/bytes.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/pkg/bytes/bytes.go b/src/pkg/bytes/bytes.go
index 31cf89ea87..6d40af4436 100644
--- a/src/pkg/bytes/bytes.go
+++ b/src/pkg/bytes/bytes.go
@@ -571,7 +571,10 @@ func indexFunc(s []byte, f func(r rune) bool, truth bool) int {
// inverted.
func lastIndexFunc(s []byte, f func(r rune) bool, truth bool) int {
for i := len(s); i > 0; {
- r, size := utf8.DecodeLastRune(s[0:i])
+ r, size := rune(s[i-1]), 1
+ if r >= utf8.RuneSelf {
+ r, size = utf8.DecodeLastRune(s[0:i])
+ }
i -= size
if f(r) == truth {
return i