From 011e40da85bddf83fee0ded83cb9115b7a88b3d4 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 26 Oct 2024 00:48:33 +0700 Subject: all: prealloc slice with possible minimum capabilities --- src/net/http/cookiejar/jar.go | 2 +- src/net/http/fs.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/net/http') diff --git a/src/net/http/cookiejar/jar.go b/src/net/http/cookiejar/jar.go index db6bcddb26..bad2a67f13 100644 --- a/src/net/http/cookiejar/jar.go +++ b/src/net/http/cookiejar/jar.go @@ -219,7 +219,7 @@ func (j *Jar) cookies(u *url.URL, now time.Time) (cookies []*http.Cookie) { } modified := false - var selected []entry + selected := make([]entry, 0, len(submap)) for id, e := range submap { if e.Persistent && !e.Expires.After(now) { delete(submap, id) diff --git a/src/net/http/fs.go b/src/net/http/fs.go index 92bd94f72d..477d341f0b 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -1020,7 +1020,9 @@ func parseRange(s string, size int64) ([]httpRange, error) { if !strings.HasPrefix(s, b) { return nil, errors.New("invalid range") } - var ranges []httpRange + + splits := strings.Split(s[len(b):], ",") + ranges := make([]httpRange, 0, len(splits)) noOverlap := false for ra := range strings.SplitSeq(s[len(b):], ",") { ra = textproto.TrimString(ra) -- cgit v1.3