Skip to content

Commit 73fa90e

Browse files
cuonglmRobert Griesemer
authored and
Robert Griesemer
committed
types2, go/types: use slices.SortFunc
Now that we're bootstrapping from a toolchain that has the slices package. Updates #64751 Change-Id: I3227e55f87e033dae63a2d1712b7f9373fe49731 Reviewed-on: https://go-review.googlesource.com/c/go/+/610603 Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Cuong Manh Le <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 2707d42 commit 73fa90e

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/cmd/compile/internal/types2/initorder.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
package types2
66

77
import (
8+
"cmp"
89
"container/heap"
910
"fmt"
1011
. "internal/types/errors"
11-
"sort"
12+
"slices"
1213
)
1314

1415
// initOrder computes the Info.InitOrder for package variables.
@@ -257,8 +258,8 @@ func dependencyGraph(objMap map[Object]*declInfo) []*graphNode {
257258
// throughout the function graph, the cost of removing a function at
258259
// position X is proportional to cost * (len(funcG)-X). Therefore, we should
259260
// remove high-cost functions last.
260-
sort.Slice(funcG, func(i, j int) bool {
261-
return funcG[i].cost() < funcG[j].cost()
261+
slices.SortFunc(funcG, func(a, b *graphNode) int {
262+
return cmp.Compare(a.cost(), b.cost())
262263
})
263264
for _, n := range funcG {
264265
// connect each predecessor p of n with each successor s

src/cmd/compile/internal/types2/stmt.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"go/constant"
1212
"internal/buildcfg"
1313
. "internal/types/errors"
14-
"sort"
14+
"slices"
1515
)
1616

1717
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *syntax.BlockStmt, iota constant.Value) {
@@ -60,8 +60,8 @@ func (check *Checker) usage(scope *Scope) {
6060
unused = append(unused, v)
6161
}
6262
}
63-
sort.Slice(unused, func(i, j int) bool {
64-
return cmpPos(unused[i].pos, unused[j].pos) < 0
63+
slices.SortFunc(unused, func(a, b *Var) int {
64+
return cmpPos(a.pos, b.pos)
6565
})
6666
for _, v := range unused {
6767
check.softErrorf(v.pos, UnusedVar, "declared and not used: %s", v.name)

src/go/types/initorder.go

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/go/types/stmt.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"go/token"
1313
"internal/buildcfg"
1414
. "internal/types/errors"
15-
"sort"
15+
"slices"
1616
)
1717

1818
func (check *Checker) funcBody(decl *declInfo, name string, sig *Signature, body *ast.BlockStmt, iota constant.Value) {
@@ -61,8 +61,8 @@ func (check *Checker) usage(scope *Scope) {
6161
unused = append(unused, v)
6262
}
6363
}
64-
sort.Slice(unused, func(i, j int) bool {
65-
return cmpPos(unused[i].pos, unused[j].pos) < 0
64+
slices.SortFunc(unused, func(a, b *Var) int {
65+
return cmpPos(a.pos, b.pos)
6666
})
6767
for _, v := range unused {
6868
check.softErrorf(v, UnusedVar, "declared and not used: %s", v.name)

0 commit comments

Comments
 (0)