]> Cypherpunks repositories - gostls13.git/commitdiff
archive/tar: preallocate slice from paxHeaders
authorGyu-Ho Lee <gyuhox@gmail.com>
Sun, 5 Jun 2016 06:08:19 +0000 (23:08 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Tue, 16 Aug 2016 02:46:50 +0000 (02:46 +0000)
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>

src/archive/tar/writer.go

index 426e4434eb75444a81e86e86bb7b07f9aaae2d8e..6acc055ca481e88f505ab4e9c12a5ea10c4e583b 100644 (file)
@@ -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)
        }