diff options
author | Gyu-Ho Lee <gyuhox@gmail.com> | 2016-06-04 23:08:19 -0700 |
---|---|---|
committer | Joe Tsai <thebrokentoaster@gmail.com> | 2016-08-16 02:46:50 +0000 |
commit | 77e68ea78abc08f827041384e0198576da44db9f (patch) | |
tree | 8531eaa617f2d078eb44a0c5febd8074bce09871 | |
parent | 2cb471e40dfe3d3ae1b0c777e67f3737a823ae79 (diff) | |
download | go-77e68ea78abc08f827041384e0198576da44db9f.tar.gz go-77e68ea78abc08f827041384e0198576da44db9f.zip |
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 <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
-rw-r--r-- | src/archive/tar/writer.go | 2 |
1 files changed, 1 insertions, 1 deletions
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) } |