aboutsummaryrefslogtreecommitdiff
path: root/src/archive
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2024-10-02 13:00:17 +0200
committerGopher Robot <gobot@golang.org>2024-10-02 14:22:59 +0000
commitbb5339196f86057ffa6042d31f52a44bf7f13752 (patch)
tree20b17a10fceb171501e121b0ace7d95f532e69cd /src/archive
parente86982c515ba4a494fb1f8e1367f4238a2b59c2e (diff)
downloadgo-bb5339196f86057ffa6042d31f52a44bf7f13752.tar.xz
all: use slices.Sorted(maps.Keys(m))
Use slices.Sorted(maps.Keys(m)) to get a sorted slices of the keys in a map. Do not change packages built during bootstrap, as the bootstrap compiler (currently 1.22.6) does not have the required maps and slices functions. Change-Id: Ie35565d241fa14aca56b730a69af010127b659ab Reviewed-on: https://go-review.googlesource.com/c/go/+/617356 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Diffstat (limited to 'src/archive')
-rw-r--r--src/archive/tar/writer.go11
1 files changed, 3 insertions, 8 deletions
diff --git a/src/archive/tar/writer.go b/src/archive/tar/writer.go
index dcefc2a8f8..059669767f 100644
--- a/src/archive/tar/writer.go
+++ b/src/archive/tar/writer.go
@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"io/fs"
+ "maps"
"path"
"slices"
"strings"
@@ -169,16 +170,10 @@ func (tw *Writer) writePAXHeader(hdr *Header, paxHdrs map[string]string) error {
// Write PAX records to the output.
isGlobal := hdr.Typeflag == TypeXGlobalHeader
if len(paxHdrs) > 0 || isGlobal {
- // Sort keys for deterministic ordering.
- var keys []string
- for k := range paxHdrs {
- keys = append(keys, k)
- }
- slices.Sort(keys)
-
// Write each record to a buffer.
var buf strings.Builder
- for _, k := range keys {
+ // Sort keys for deterministic ordering.
+ for _, k := range slices.Sorted(maps.Keys(paxHdrs)) {
rec, err := formatPAXRecord(k, paxHdrs[k])
if err != nil {
return err