From: Gyu-Ho Lee Date: Sun, 5 Jun 2016 06:08:19 +0000 (-0700) Subject: archive/tar: preallocate slice from paxHeaders X-Git-Tag: go1.8beta1~1869 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=77e68ea78abc08f827041384e0198576da44db9f;p=gostls13.git 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 --- 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) }