From: Cuong Manh Le Date: Wed, 4 Sep 2024 18:18:10 +0000 (+0700) Subject: types2, go/types: use slices.SortFunc X-Git-Tag: go1.24rc1~996 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=73fa90e2908d525efb9f7ad0dbcfceb5f25c7251;p=gostls13.git 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 Auto-Submit: Cuong Manh Le LUCI-TryBot-Result: Go LUCI Reviewed-by: Robert Findley --- 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)