From 052a3cfb650e47571e9f876e3f5e9bb4f1b2bf16 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Sat, 19 Dec 2015 20:44:01 +0200 Subject: [PATCH] Substitute EqualBytesStr(s, b) by string(b) == s --- args.go | 2 +- bytesconv.go | 2 ++ bytesconv_timing_test.go | 35 ----------------------------------- client_test.go | 2 +- client_timing_test.go | 4 ++-- 5 files changed, 6 insertions(+), 39 deletions(-) diff --git a/args.go b/args.go index 079f954..cd63d67 100644 --- a/args.go +++ b/args.go @@ -328,7 +328,7 @@ func peekArgBytes(h []argsKV, k []byte) []byte { func peekArgStr(h []argsKV, k string) []byte { for i, n := 0, len(h); i < n; i++ { kv := &h[i] - if EqualBytesStr(kv.key, k) { + if string(kv.key) == k { return kv.value } } diff --git a/bytesconv.go b/bytesconv.go index e354078..b21fbe8 100644 --- a/bytesconv.go +++ b/bytesconv.go @@ -324,6 +324,8 @@ func appendQuotedArg(dst, v []byte) []byte { // // This function has no performance benefits comparing to string(b) == s. // It is left here for backwards compatibility only. +// +// This function is deperecated and may be deleted soon. func EqualBytesStr(b []byte, s string) bool { return string(b) == s } diff --git a/bytesconv_timing_test.go b/bytesconv_timing_test.go index ef87973..6aa05a8 100644 --- a/bytesconv_timing_test.go +++ b/bytesconv_timing_test.go @@ -133,38 +133,3 @@ func BenchmarkLowercaseBytesMixed(b *testing.B) { } }) } - -func BenchmarkEqualBytesStrEq(b *testing.B) { - s := "foobarbaraz" - bs := []byte(s) - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - if !EqualBytesStr(bs, s) { - b.Fatalf("unexpected result: %q != %q", bs, s) - } - } - }) -} - -func BenchmarkEqualBytesStrNe(b *testing.B) { - s := "foobarbaraz" - bs := []byte(s) - bs[len(s)-1] = 'a' - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - if EqualBytesStr(bs, s) { - b.Fatalf("unexpected result: %q = %q", bs, s) - } - } - }) -} - -func BenchmarkAppendBytesStr(b *testing.B) { - s := "foobarbazbaraz" - b.RunParallel(func(pb *testing.PB) { - var dst []byte - for pb.Next() { - dst = AppendBytesStr(dst[:0], s) - } - }) -} diff --git a/client_test.go b/client_test.go index 0014eb1..0b23426 100644 --- a/client_test.go +++ b/client_test.go @@ -16,7 +16,7 @@ func TestClientFollowRedirects(t *testing.T) { addr := "127.0.0.1:55234" s := &Server{ Handler: func(ctx *RequestCtx) { - if EqualBytesStr(ctx.Path(), "/foo") { + if string(ctx.Path()) == "/foo" { u := ctx.URI() u.Update("/bar") ctx.Redirect(u.String(), StatusFound) diff --git a/client_timing_test.go b/client_timing_test.go index ec8f5b8..f1261c7 100644 --- a/client_timing_test.go +++ b/client_timing_test.go @@ -201,7 +201,7 @@ func BenchmarkClientGetEndToEnd(b *testing.B) { if statusCode != StatusOK { b.Fatalf("unexpected status code: %d. Expecting %d", statusCode, StatusOK) } - if !EqualBytesStr(body, requestURI) { + if string(body) != requestURI { b.Fatalf("unexpected response %q. Expecting %q", body, requestURI) } buf = body @@ -249,7 +249,7 @@ func BenchmarkNetHTTPClientGetEndToEnd(b *testing.B) { if err != nil { b.Fatalf("unexpected error when reading response body: %s", err) } - if !EqualBytesStr(body, requestURI) { + if string(body) != requestURI { b.Fatalf("unexpected response %q. Expecting %q", body, requestURI) } }