cmd: replace many sort.Interface with slices.Sort and SortFunc

with slices there's no need to implement sort.Interface

Change-Id: I59167e78881cb1df89a71e33d738d6aeca7adb71
GitHub-Last-Rev: 507ba84453
GitHub-Pull-Request: golang/go#68724
Reviewed-on: https://go-review.googlesource.com/c/go/+/602895
Reviewed-by: Ian Lance Taylor <iant@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
This commit is contained in:
Zxilly 2024-09-03 17:46:10 +00:00 committed by Keith Randall
parent 7cd0a4be5c
commit d91a2e5b11
38 changed files with 239 additions and 417 deletions

View file

@ -9,7 +9,7 @@ import (
"cmd/internal/objabi"
"fmt"
"log"
"sort"
"slices"
)
// ctxt0 holds state while assembling a single function.
@ -964,36 +964,20 @@ func cmp(a int, b int) bool {
return false
}
type ocmp []Optab
func (x ocmp) Len() int {
return len(x)
}
func (x ocmp) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
func (x ocmp) Less(i, j int) bool {
p1 := &x[i]
p2 := &x[j]
n := int(p1.as) - int(p2.as)
if n != 0 {
return n < 0
func ocmp(p1, p2 Optab) int {
if p1.as != p2.as {
return int(p1.as) - int(p2.as)
}
n = int(p1.from1) - int(p2.from1)
if n != 0 {
return n < 0
if p1.from1 != p2.from1 {
return int(p1.from1) - int(p2.from1)
}
n = int(p1.reg) - int(p2.reg)
if n != 0 {
return n < 0
if p1.reg != p2.reg {
return int(p1.reg) - int(p2.reg)
}
n = int(p1.to1) - int(p2.to1)
if n != 0 {
return n < 0
if p1.to1 != p2.to1 {
return int(p1.to1) - int(p2.to1)
}
return false
return 0
}
func opset(a, b0 obj.As) {
@ -1025,7 +1009,7 @@ func buildop(ctxt *obj.Link) {
}
for n = 0; optab[n].as != obj.AXXX; n++ {
}
sort.Sort(ocmp(optab[:n]))
slices.SortFunc(optab[:n], ocmp)
for i := 0; i < n; i++ {
r := optab[i].as
r0 := r & obj.AMask