Skip to content

Commit d0094e7

Browse files
committed
cmd: use slices to simplify the code
Go 1.26 and later requires Go 1.24.6 as the minimum bootstrap toolchain, so it is now safe to replace “sort.Strings/Ints/...” with “slices.Sort/Sorted” and simplify the code. Updates #57433
1 parent f86ddb5 commit d0094e7

File tree

41 files changed

+84
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+84
-102
lines changed

src/cmd/asm/internal/asm/endtoend_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"os"
1313
"path/filepath"
1414
"regexp"
15-
"sort"
15+
"slices"
1616
"strconv"
1717
"strings"
1818
"testing"
@@ -245,7 +245,7 @@ Diff:
245245
for key := range hexByLine {
246246
missing = append(missing, key)
247247
}
248-
sort.Strings(missing)
248+
slices.Sort(missing)
249249
for _, line := range missing {
250250
t.Errorf("%s: did not find instruction encoding", line)
251251
}
@@ -367,7 +367,7 @@ func testErrors(t *testing.T, goarch, file string, flags ...string) {
367367
for key := range errors {
368368
extra = append(extra, key)
369369
}
370-
sort.Strings(extra)
370+
slices.Sort(extra)
371371
for _, fileline := range extra {
372372
t.Errorf("unexpected error on %s: %v", fileline, errors[fileline])
373373
}

src/cmd/cgo/internal/testshared/shared_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"path/filepath"
2323
"regexp"
2424
"runtime"
25-
"sort"
25+
"slices"
2626
"strconv"
2727
"strings"
2828
"testing"
@@ -232,7 +232,7 @@ func cloneGOROOTDeps(goroot string) error {
232232

233233
pkgs := append(strings.Split(strings.TrimSpace(stdDeps), "\n"),
234234
strings.Split(strings.TrimSpace(testdataDeps), "\n")...)
235-
sort.Strings(pkgs)
235+
slices.Sort(pkgs)
236236
var pkgRoots []string
237237
for _, pkg := range pkgs {
238238
parentFound := false

src/cmd/cgo/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"path/filepath"
2424
"reflect"
2525
"runtime"
26-
"sort"
26+
"slices"
2727
"strings"
2828
"sync"
2929

@@ -88,7 +88,7 @@ func nameKeys(m map[string]*Name) []string {
8888
for k := range m {
8989
ks = append(ks, k)
9090
}
91-
sort.Strings(ks)
91+
slices.Sort(ks)
9292
return ks
9393
}
9494

src/cmd/cgo/out.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os/exec"
2121
"path/filepath"
2222
"regexp"
23-
"sort"
23+
"slices"
2424
"strings"
2525
"unicode"
2626
)
@@ -120,7 +120,7 @@ func (p *Package) writeDefs() {
120120
}
121121
typedefNames = append(typedefNames, name)
122122
}
123-
sort.Strings(typedefNames)
123+
slices.Sort(typedefNames)
124124
for _, name := range typedefNames {
125125
def := typedef[name]
126126
fmt.Fprintf(fgo2, "type %s ", name)

src/cmd/compile/internal/inline/inlheur/callsite.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"fmt"
1212
"io"
1313
"path/filepath"
14-
"sort"
14+
"slices"
1515
"strings"
1616
)
1717

@@ -140,7 +140,7 @@ func dumpCallSiteComments(w io.Writer, tab CallSiteTab, ecst encodedCallSiteTab)
140140
for k := range ecst {
141141
tags = append(tags, k)
142142
}
143-
sort.Strings(tags)
143+
slices.Sort(tags)
144144
for _, s := range tags {
145145
v := ecst[s]
146146
fmt.Fprintf(w, "// callsite: %s flagstr %q flagval %d score %d mask %d maskstr %q\n", s, v.props.String(), v.props, v.score, v.mask, v.mask.String())

src/cmd/compile/internal/liveness/intervals_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"fmt"
1010
"math/rand"
1111
"os"
12-
"sort"
12+
"slices"
1313
"testing"
1414
)
1515

@@ -306,7 +306,7 @@ func TestRandomIntervalsOverlap(t *testing.T) {
306306
// decide how many segments
307307
segs := rand.Intn(int(*segsflag))
308308
picked := vals[:(segs * 2)]
309-
sort.Ints(picked)
309+
slices.Sort(picked)
310310
ii, err := makeIntervals(picked...)
311311
if err != nil {
312312
t.Fatalf("makeIntervals(%+v) returns err %v", picked, err)

src/cmd/compile/internal/liveness/plive.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"os"
2121
"slices"
22-
"sort"
2322
"strings"
2423

2524
"cmd/compile/internal/abi"
@@ -1163,7 +1162,7 @@ func (lv *Liveness) format(v *ssa.Value, live bitvec.BitVec) (src.XPos, string)
11631162
names = append(names, n.Sym().Name)
11641163
}
11651164
}
1166-
sort.Strings(names)
1165+
slices.Sort(names)
11671166
for _, v := range names {
11681167
s += " " + v
11691168
}

src/cmd/compile/internal/ssa/_gen/rulegen.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"os"
2626
"path"
2727
"regexp"
28-
"sort"
28+
"slices"
2929
"strconv"
3030
"strings"
3131

@@ -170,7 +170,7 @@ func genRulesSuffix(arch arch, suff string) {
170170
for op := range oprules {
171171
ops = append(ops, op)
172172
}
173-
sort.Strings(ops)
173+
slices.Sort(ops)
174174

175175
genFile := &File{Arch: arch, Suffix: suff}
176176
// Main rewrite routine is a switch on v.Op.
@@ -257,7 +257,7 @@ func genRulesSuffix(arch arch, suff string) {
257257
for op := range blockrules {
258258
ops = append(ops, op)
259259
}
260-
sort.Strings(ops)
260+
slices.Sort(ops)
261261
for _, op := range ops {
262262
name, data := getBlockInfo(op, arch)
263263
swc := &Case{Expr: exprf("%s", name)}

src/cmd/compile/internal/ssa/compile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"path/filepath"
1717
"regexp"
1818
"runtime"
19-
"sort"
19+
"slices"
2020
"strings"
2121
"time"
2222
)
@@ -150,7 +150,7 @@ func Compile(f *Func) {
150150
for key := range f.ruleMatches {
151151
keys = append(keys, key)
152152
}
153-
sort.Strings(keys)
153+
slices.Sort(keys)
154154
buf := new(strings.Builder)
155155
fmt.Fprintf(buf, "%s: ", f.Name)
156156
for _, key := range keys {

src/cmd/compile/internal/ssa/value.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"cmd/internal/src"
1111
"fmt"
1212
"math"
13-
"sort"
13+
"slices"
1414
"strings"
1515
)
1616

@@ -182,7 +182,7 @@ func (v *Value) LongString() string {
182182
}
183183
}
184184
if len(names) != 0 {
185-
sort.Strings(names) // Otherwise a source of variation in debugging output.
185+
slices.Sort(names) // Otherwise a source of variation in debugging output.
186186
s += " (" + strings.Join(names, ", ") + ")"
187187
}
188188
return s

0 commit comments

Comments
 (0)