diff --git a/staging/src/k8s.io/apimachinery/pkg/util/net/http.go b/staging/src/k8s.io/apimachinery/pkg/util/net/http.go index ba63d02df69..567a294e26c 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/net/http.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/net/http.go @@ -693,7 +693,7 @@ func parseQuotedString(quotedString string) (string, string, error) { var remainder string escaping := false closedQuote := false - result := &bytes.Buffer{} + result := &strings.Builder{} loop: for i := 0; i < len(quotedString); i++ { b := quotedString[i] diff --git a/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go b/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go index a43161b88b7..9411bfa7ddf 100644 --- a/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go +++ b/staging/src/k8s.io/apimachinery/pkg/util/net/http_test.go @@ -1107,3 +1107,21 @@ func TestPingTimeoutSeconds(t *testing.T) { } reset() } + +func Benchmark_ParseQuotedString(b *testing.B) { + str := `"The quick brown" fox jumps over the lazy dog` + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + quoted, remainder, err := parseQuotedString(str) + if err != nil { + b.Errorf("Unexpected error %s", err) + } + if quoted != "The quick brown" { + b.Errorf("Unexpected quoted string %s", quoted) + } + if remainder != "fox jumps over the lazy dog" { + b.Errorf("Unexpected remainder string %s", quoted) + } + } +}