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>
package strconv
-import "unicode/utf8"
+import (
+ "internal/bytealg"
+ "unicode/utf8"
+)
const lowerhex = "0123456789abcdef"
// 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.