diff --git a/src/cmd/compile/internal/types2/initorder.go b/src/cmd/compile/internal/types2/initorder.go index 86cb9036c4..09a53c98ef 100644 --- a/src/cmd/compile/internal/types2/initorder.go +++ b/src/cmd/compile/internal/types2/initorder.go @@ -5,10 +5,11 @@ package types2 import ( + "cmp" "container/heap" "fmt" . "internal/types/errors" - "sort" + "slices" ) // initOrder computes the Info.InitOrder for package variables. @@ -257,8 +258,8 @@ func dependencyGraph(objMap map[Object]*declInfo) []*graphNode { // throughout the function graph, the cost of removing a function at // position X is proportional to cost * (len(funcG)-X). Therefore, we should // remove high-cost functions last. - sort.Slice(funcG, func(i, j int) bool { - return funcG[i].cost() < funcG[j].cost() + slices.SortFunc(funcG, func(a, b *graphNode) int { + return cmp.Compare(a.cost(), b.cost()) }) for _, n := range funcG { // connect each predecessor p of n with each successor s diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index c381187fd3..ac22f89ab8 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -11,7 +11,7 @@ import ( "go/constant" "internal/buildcfg" . "internal/types/errors" - "sort" + "slices" ) 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) { unused = append(unused, v) } } - sort.Slice(unused, func(i, j int) bool { - return cmpPos(unused[i].pos, unused[j].pos) < 0 + slices.SortFunc(unused, func(a, b *Var) int { + return cmpPos(a.pos, b.pos) }) for _, v := range unused { check.softErrorf(v.pos, UnusedVar, "declared and not used: %s", v.name) diff --git a/src/go/types/initorder.go b/src/go/types/initorder.go index e539219773..077f2eccfe 100644 --- a/src/go/types/initorder.go +++ b/src/go/types/initorder.go @@ -8,10 +8,11 @@ package types import ( + "cmp" "container/heap" "fmt" . "internal/types/errors" - "sort" + "slices" ) // initOrder computes the Info.InitOrder for package variables. @@ -260,8 +261,8 @@ func dependencyGraph(objMap map[Object]*declInfo) []*graphNode { // throughout the function graph, the cost of removing a function at // position X is proportional to cost * (len(funcG)-X). Therefore, we should // remove high-cost functions last. - sort.Slice(funcG, func(i, j int) bool { - return funcG[i].cost() < funcG[j].cost() + slices.SortFunc(funcG, func(a, b *graphNode) int { + return cmp.Compare(a.cost(), b.cost()) }) for _, n := range funcG { // connect each predecessor p of n with each successor s diff --git a/src/go/types/stmt.go b/src/go/types/stmt.go index f8514fdbb7..b1346bb27e 100644 --- a/src/go/types/stmt.go +++ b/src/go/types/stmt.go @@ -12,7 +12,7 @@ import ( "go/token" "internal/buildcfg" . "internal/types/errors" - "sort" + "slices" ) 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) { unused = append(unused, v) } } - sort.Slice(unused, func(i, j int) bool { - return cmpPos(unused[i].pos, unused[j].pos) < 0 + slices.SortFunc(unused, func(a, b *Var) int { + return cmpPos(a.pos, b.pos) }) for _, v := range unused { check.softErrorf(v, UnusedVar, "declared and not used: %s", v.name)