diff options
author | Shulhan <ms@kilabit.info> | 2019-01-31 01:26:08 +0700 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-01-30 20:42:28 +0100 |
commit | 4c53f113c5e6b3399fd93214f0bd1b5d5f19f1a5 (patch) | |
tree | 17ca0788c62562ea3f9c93932fbc6956007a974d /cookie_test.go | |
parent | Add warning to DoTimeout (diff) | |
download | fasthttp-4c53f113c5e6b3399fd93214f0bd1b5d5f19f1a5.tar.gz fasthttp-4c53f113c5e6b3399fd93214f0bd1b5d5f19f1a5.tar.bz2 fasthttp-4c53f113c5e6b3399fd93214f0bd1b5d5f19f1a5.zip |
all: pre-allocated slice with possible known size
This fix is based on suggestion of "prealloc" static analysis tool [1].
Per note of the tool's author suggestion, its recommended to allocate the
slice length/capability, if we known their possible size. This is to
minimize "append" to re-allocate the slice underlying array.
[1] https://github.com/alexkohler/prealloc
Diffstat (limited to 'cookie_test.go')
-rw-r--r-- | cookie_test.go | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/cookie_test.go b/cookie_test.go index c11a942..50c2ad3 100644 --- a/cookie_test.go +++ b/cookie_test.go @@ -98,7 +98,7 @@ func TestCookieSameSite(t *testing.T) { if !strings.Contains(s, "; SameSite") { t.Fatalf("missing SameSite flag in cookie %q", s) } - + if err := c.Parse("foo=bar; samesite=lax"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -109,7 +109,7 @@ func TestCookieSameSite(t *testing.T) { if !strings.Contains(s, "; SameSite=Lax") { t.Fatalf("missing SameSite flag in cookie %q", s) } - + if err := c.Parse("foo=bar; samesite=strict"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -120,7 +120,7 @@ func TestCookieSameSite(t *testing.T) { if !strings.Contains(s, "; SameSite=Strict") { t.Fatalf("missing SameSite flag in cookie %q", s) } - + if err := c.Parse("foo=bar"); err != nil { t.Fatalf("unexpected error: %s", err) } @@ -333,8 +333,9 @@ func TestAppendRequestCookieBytes(t *testing.T) { } func testAppendRequestCookieBytes(t *testing.T, s, expectedS string) { - var cookies []argsKV - for _, ss := range strings.Split(s, "&") { + kvs := strings.Split(s, "&") + cookies := make([]argsKV, 0, len(kvs)) + for _, ss := range kvs { tmp := strings.SplitN(ss, "=", 2) if len(tmp) != 2 { t.Fatalf("Cannot find '=' in %q, part of %q", ss, s) |