]> Cypherpunks repositories - gostls13.git/commitdiff
strconv: use bytealg implementation of IndexByteString
authorTim Cooper <tim.cooper@layeh.com>
Wed, 6 Jun 2018 19:23:44 +0000 (16:23 -0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 22 Aug 2018 17:04:01 +0000 (17:04 +0000)
    benchmark                  old ns/op     new ns/op     delta
    BenchmarkUnquoteEasy-4     188           79.5          -57.71%
    BenchmarkUnquoteHard-4     653           622           -4.75%

Fixes #23821

Change-Id: I1ebfab1b7f0248fd313de21396e0f8612076aa6d
Reviewed-on: https://go-review.googlesource.com/116755
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/strconv/quote.go

index 9b7194a0f041d456de6d51c6b16174f9b6062df8..6cd2f93068c03c36af8a48fdfc356be629b81360 100644 (file)
@@ -6,7 +6,10 @@
 
 package strconv
 
-import "unicode/utf8"
+import (
+       "internal/bytealg"
+       "unicode/utf8"
+)
 
 const lowerhex = "0123456789abcdef"
 
@@ -424,12 +427,7 @@ func Unquote(s string) (string, error) {
 
 // contains reports whether the string contains the byte c.
 func contains(s string, c byte) bool {
-       for i := 0; i < len(s); i++ {
-               if s[i] == c {
-                       return true
-               }
-       }
-       return false
+       return bytealg.IndexByteString(s, c) != -1
 }
 
 // bsearch16 returns the smallest i such that a[i] >= x.