Skip to content

Commit

Permalink
archive/tar: preallocate slice from paxHeaders
Browse files Browse the repository at this point in the history
Preallocate keys slice with the length of paxHeaders map
to prevent slice growth with append operations.

Change-Id: Ic9a927c4eaa775690a4ef912d61dd06f38e11510
Reviewed-on: https://go-review.googlesource.com/23782
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
gyuho authored and dsnet committed Aug 16, 2016
1 parent 2cb471e commit 77e68ea
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/archive/tar/writer.go
Expand Up @@ -317,7 +317,7 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHeaders map[string]string) erro
var buf bytes.Buffer

// Keys are sorted before writing to body to allow deterministic output.
var keys []string
keys := make([]string, 0, len(paxHeaders))
for k := range paxHeaders {
keys = append(keys, k)
}
Expand Down

0 comments on commit 77e68ea

Please sign in to comment.