Skip to content

Commit 77e68ea

Browse files
gyuhodsnet
authored andcommitted
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 <[email protected]> Run-TryBot: Joe Tsai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 2cb471e commit 77e68ea

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/archive/tar/writer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHeaders map[string]string) erro
317317
var buf bytes.Buffer
318318

319319
// Keys are sorted before writing to body to allow deterministic output.
320-
var keys []string
320+
keys := make([]string, 0, len(paxHeaders))
321321
for k := range paxHeaders {
322322
keys = append(keys, k)
323323
}

0 commit comments

Comments
 (0)