]> Cypherpunks repositories - gostls13.git/commitdiff
types2, go/types: use slices.SortFunc
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Wed, 4 Sep 2024 18:18:10 +0000 (01:18 +0700)
committerRobert Griesemer <gri@google.com>
Thu, 5 Sep 2024 16:39:57 +0000 (16:39 +0000)
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 <gri@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/initorder.go
src/cmd/compile/internal/types2/stmt.go
src/go/types/initorder.go
src/go/types/stmt.go

index 86cb9036c4cd93595d5a7fc8ded0d6b66fe69014..09a53c98efe14ce92e41e5981790563552107584 100644 (file)
@@ -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
index c381187fd3a448d295a1e3e87a992f46d76be84d..ac22f89ab8eb181048421eb160ac5c5de5bdabd3 100644 (file)
@@ -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)
index e539219773bb324fb572c73fbdd0a6adc1e0dbfc..077f2eccfe086db6ee459d7d8ccdbc0812b44c8e 100644 (file)
@@ -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
index f8514fdbb79ee43e8ca752465982b0e1cdca6661..b1346bb27ed3810470f0f5725b62ad1d29bd86a8 100644 (file)
@@ -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)