mirror of
https://github.com/valyala/fasthttp.git
synced 2026-06-14 15:56:44 +03:00
Substitute EqualBytesStr(s, b) by string(b) == s
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user