Substitute EqualBytesStr(s, b) by string(b) == s

This commit is contained in:
Aliaksandr Valialkin
2015-12-19 20:44:01 +02:00
parent 5ff6be8fee
commit 052a3cfb65
5 changed files with 6 additions and 39 deletions
+1 -1
View File
@@ -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
}
}
+2
View File
@@ -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
}
-35
View File
@@ -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)
}
})
}
+1 -1
View File
@@ -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)
+2 -2
View File
@@ -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)
}
}