pre allocate slices

Pre allocating slices with a target size reduces the number of allocations because we already know how big the slice will be and therefore need to allocate only once
This commit is contained in:
David Christofas
2021-02-22 19:41:48 +01:00
parent e535975718
commit 1088faf95d
7 changed files with 8 additions and 8 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ type Resolutions []image.Rectangle
// ParseResolutions creates an instance of Resolutions from resolution strings.
func ParseResolutions(strs []string) (Resolutions, error) {
var rs Resolutions
rs := make(Resolutions, 0, len(strs))
for _, s := range strs {
r, err := ParseResolution(s)
if err != nil {