From 5ddecd150821713c53de15f439c7925b28c9f535 Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Wed, 6 Jun 2018 16:23:44 -0300 Subject: [PATCH] strconv: use bytealg implementation of IndexByteString 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/strconv/quote.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/strconv/quote.go b/src/strconv/quote.go index 9b7194a0f0..6cd2f93068 100644 --- a/src/strconv/quote.go +++ b/src/strconv/quote.go @@ -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. -- 2.50.0