Skip to content

Commit 32bd777

Browse files
cuonglmgopherbot
authored andcommitted
cmd/compile: use slices.SortStableFunc
Now that we're bootstrapping from a toolchain that has the slices package. Updates #64751 Change-Id: I876ec6d261466344faf33f8c5cda229dd1e4185f Reviewed-on: https://go-review.googlesource.com/c/go/+/610602 Auto-Submit: Cuong Manh Le <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent f15095f commit 32bd777

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
"cmd/compile/internal/base"
99
"cmd/compile/internal/ir"
1010
"cmd/compile/internal/types"
11+
"cmp"
1112
"encoding/json"
1213
"fmt"
1314
"internal/buildcfg"
1415
"io"
1516
"os"
1617
"path/filepath"
17-
"sort"
18+
"slices"
1819
"strings"
1920
)
2021

@@ -349,11 +350,11 @@ func dumpFnPreamble(w io.Writer, funcInlHeur *fnInlHeur, ecst encodedCallSiteTab
349350
// sortFnInlHeurSlice sorts a slice of fnInlHeur based on
350351
// the starting line of the function definition, then by name.
351352
func sortFnInlHeurSlice(sl []fnInlHeur) []fnInlHeur {
352-
sort.SliceStable(sl, func(i, j int) bool {
353-
if sl[i].line != sl[j].line {
354-
return sl[i].line < sl[j].line
353+
slices.SortStableFunc(sl, func(a, b fnInlHeur) int {
354+
if a.line != b.line {
355+
return cmp.Compare(a.line, b.line)
355356
}
356-
return sl[i].fname < sl[j].fname
357+
return strings.Compare(a.fname, b.fname)
357358
})
358359
return sl
359360
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ func (mls *MergeLocalsState) Followers(n *ir.Name, tmp []*ir.Name) []*ir.Name {
161161
for _, k := range sl[1:] {
162162
tmp = append(tmp, mls.vars[k])
163163
}
164-
sort.SliceStable(tmp, func(i, j int) bool {
165-
return tmp[i].Sym().Name < tmp[j].Sym().Name
164+
slices.SortStableFunc(tmp, func(a, b *ir.Name) int {
165+
return strings.Compare(a.Sym().Name, b.Sym().Name)
166166
})
167167
return tmp
168168
}

0 commit comments

Comments
 (0)