package types2
import (
+ "cmp"
"container/heap"
"fmt"
. "internal/types/errors"
- "sort"
+ "slices"
)
// initOrder computes the Info.InitOrder for package variables.
// 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
"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) {
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)
package types
import (
+ "cmp"
"container/heap"
"fmt"
. "internal/types/errors"
- "sort"
+ "slices"
)
// initOrder computes the Info.InitOrder for package variables.
// 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
"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) {
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)