Skip to content

Commit

Permalink
types2, go/types: use slices.SortFunc
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cuonglm authored and Robert Griesemer committed Sep 5, 2024
1 parent 2707d42 commit 73fa90e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/cmd/compile/internal/types2/initorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package types2

import (
"cmp"
"container/heap"
"fmt"
. "internal/types/errors"
"sort"
"slices"
)

// initOrder computes the Info.InitOrder for package variables.
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/compile/internal/types2/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions src/go/types/initorder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/go/types/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 73fa90e

Please sign in to comment.