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

@ -7,12 +7,13 @@ package objfile
import (
"cmd/internal/archive"
"cmp"
"debug/dwarf"
"debug/gosym"
"fmt"
"io"
"os"
"sort"
"slices"
)
type rawFile interface {
@ -131,16 +132,12 @@ func (e *Entry) Symbols() ([]Sym, error) {
if err != nil {
return nil, err
}
sort.Sort(byAddr(syms))
slices.SortFunc(syms, func(a, b Sym) int {
return cmp.Compare(a.Addr, b.Addr)
})
return syms, nil
}
type byAddr []Sym
func (x byAddr) Less(i, j int) bool { return x[i].Addr < x[j].Addr }
func (x byAddr) Len() int { return len(x) }
func (x byAddr) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (e *Entry) PCLineTable() (Liner, error) {
// If the raw file implements Liner directly, use that.
// Currently, only Go intermediate objects and archives (goobj) use this path.