From 77e68ea78abc08f827041384e0198576da44db9f Mon Sep 17 00:00:00 2001 From: Gyu-Ho Lee Date: Sat, 4 Jun 2016 23:08:19 -0700 Subject: [PATCH] archive/tar: preallocate slice from paxHeaders 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 Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot --- src/archive/tar/writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go index 426e4434eb..6acc055ca4 100644 --- a/src/archive/tar/writer.go +++ b/src/archive/tar/writer.go @@ -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) } -- 2.48.1