From ad26bb5e3098cbfd7c0ad9a1dc9d38c92e50f06e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 4 Oct 2016 03:01:09 +0000 Subject: all: use sort.Slice where applicable I avoided anywhere in the compiler or things which might be used by the compiler in the future, since they need to build with Go 1.4. I also avoided anywhere where there was no benefit to changing it. I probably missed some. Updates #16721 Change-Id: Ib3c895ff475c6dec2d4322393faaf8cb6a6d4956 Reviewed-on: https://go-review.googlesource.com/30250 TryBot-Result: Gobot Gobot Run-TryBot: Brad Fitzpatrick Reviewed-by: Andrew Gerrand --- src/cmd/nm/nm.go | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'src/cmd/nm') diff --git a/src/cmd/nm/nm.go b/src/cmd/nm/nm.go index 462c4c510f..4384af8fae 100644 --- a/src/cmd/nm/nm.go +++ b/src/cmd/nm/nm.go @@ -103,11 +103,11 @@ func nm(file string) { switch *sortOrder { case "address": - sort.Sort(byAddr(syms)) + sort.Slice(syms, func(i, j int) bool { return syms[i].Addr < syms[j].Addr }) case "name": - sort.Sort(byName(syms)) + sort.Slice(syms, func(i, j int) bool { return syms[i].Name < syms[j].Name }) case "size": - sort.Sort(bySize(syms)) + sort.Slice(syms, func(i, j int) bool { return syms[i].Size > syms[j].Size }) } w := bufio.NewWriter(os.Stdout) @@ -131,21 +131,3 @@ func nm(file string) { } w.Flush() } - -type byAddr []objfile.Sym - -func (x byAddr) Len() int { return len(x) } -func (x byAddr) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byAddr) Less(i, j int) bool { return x[i].Addr < x[j].Addr } - -type byName []objfile.Sym - -func (x byName) Len() int { return len(x) } -func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byName) Less(i, j int) bool { return x[i].Name < x[j].Name } - -type bySize []objfile.Sym - -func (x bySize) Len() int { return len(x) } -func (x bySize) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x bySize) Less(i, j int) bool { return x[i].Size > x[j].Size } -- cgit v1.3-5-g9baa