mirror of
https://github.com/golang/go
synced 2024-09-23 07:23:18 -06:00
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 <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>
This commit is contained in:
parent
2707d42966
commit
73fa90e290
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user