diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2016-10-04 03:01:09 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2016-10-04 05:10:56 +0000 |
| commit | ad26bb5e3098cbfd7c0ad9a1dc9d38c92e50f06e (patch) | |
| tree | b84cfdbe334ab18e89b3c1099814f852f42b476b /src/runtime | |
| parent | 2f184c65a5bdd422f88d841bb3a37fa60b3e1d52 (diff) | |
| download | go-ad26bb5e3098cbfd7c0ad9a1dc9d38c92e50f06e.tar.xz | |
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 <gobot@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/debug/garbage.go | 8 | ||||
| -rw-r--r-- | src/runtime/pprof/pprof.go | 24 |
2 files changed, 4 insertions, 28 deletions
diff --git a/src/runtime/debug/garbage.go b/src/runtime/debug/garbage.go index 8144497177..c82c024235 100644 --- a/src/runtime/debug/garbage.go +++ b/src/runtime/debug/garbage.go @@ -71,7 +71,7 @@ func ReadGCStats(stats *GCStats) { // See the allocation at the top of the function. sorted := stats.Pause[n : n+n] copy(sorted, stats.Pause) - sort.Sort(byDuration(sorted)) + sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] }) nq := len(stats.PauseQuantiles) - 1 for i := 0; i < nq; i++ { stats.PauseQuantiles[i] = sorted[len(sorted)*i/nq] @@ -81,12 +81,6 @@ func ReadGCStats(stats *GCStats) { } } -type byDuration []time.Duration - -func (x byDuration) Len() int { return len(x) } -func (x byDuration) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byDuration) Less(i, j int) bool { return x[i] < x[j] } - // SetGCPercent sets the garbage collection target percentage: // a collection is triggered when the ratio of freshly allocated data // to live data remaining after the previous collection reaches this percentage. diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go index 1fc9568b2f..b4dd1c4173 100644 --- a/src/runtime/pprof/pprof.go +++ b/src/runtime/pprof/pprof.go @@ -207,16 +207,10 @@ func Profiles() []*Profile { all = append(all, p) } - sort.Sort(byName(all)) + sort.Slice(all, func(i, j int) bool { return all[i].name < all[j].name }) return all } -type byName []*Profile - -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 } - // Name returns this profile's name, which can be passed to Lookup to reobtain the profile. func (p *Profile) Name() string { return p.name @@ -435,12 +429,6 @@ func printStackRecord(w io.Writer, stk []uintptr, allFrames bool) { // Interface to system profiles. -type byInUseBytes []runtime.MemProfileRecord - -func (x byInUseBytes) Len() int { return len(x) } -func (x byInUseBytes) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byInUseBytes) Less(i, j int) bool { return x[i].InUseBytes() > x[j].InUseBytes() } - // WriteHeapProfile is shorthand for Lookup("heap").WriteTo(w, 0). // It is preserved for backwards compatibility. func WriteHeapProfile(w io.Writer) error { @@ -476,7 +464,7 @@ func writeHeap(w io.Writer, debug int) error { // Profile grew; try again. } - sort.Sort(byInUseBytes(p)) + sort.Slice(p, func(i, j int) bool { return p[i].InUseBytes() > p[j].InUseBytes() }) b := bufio.NewWriter(w) var tw *tabwriter.Writer @@ -735,12 +723,6 @@ func StopCPUProfile() { <-cpu.done } -type byCycles []runtime.BlockProfileRecord - -func (x byCycles) Len() int { return len(x) } -func (x byCycles) Swap(i, j int) { x[i], x[j] = x[j], x[i] } -func (x byCycles) Less(i, j int) bool { return x[i].Cycles > x[j].Cycles } - // countBlock returns the number of records in the blocking profile. func countBlock() int { n, _ := runtime.BlockProfile(nil) @@ -760,7 +742,7 @@ func writeBlock(w io.Writer, debug int) error { } } - sort.Sort(byCycles(p)) + sort.Slice(p, func(i, j int) bool { return p[i].Cycles > p[j].Cycles }) b := bufio.NewWriter(w) var tw *tabwriter.Writer |
