diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-18 20:54:35 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-18 20:54:35 +0200 |
| commit | cd554b0af706b5f62b4e1bfde04091052b4aac61 (patch) | |
| tree | e6d02f1c2a1da27da17386e8832c2d4a3e699cdf /internal/tui/flamegraph | |
| parent | b421b2232351049277ee4ad5b31367bb2b6779bb (diff) | |
cleanup
Diffstat (limited to 'internal/tui/flamegraph')
| -rw-r--r-- | internal/tui/flamegraph/model.go | 20 | ||||
| -rw-r--r-- | internal/tui/flamegraph/renderer.go | 19 |
2 files changed, 20 insertions, 19 deletions
diff --git a/internal/tui/flamegraph/model.go b/internal/tui/flamegraph/model.go index a7b26f8..0552a4f 100644 --- a/internal/tui/flamegraph/model.go +++ b/internal/tui/flamegraph/model.go @@ -1,11 +1,11 @@ package flamegraph import ( + "cmp" "encoding/json" "fmt" "image/color" "slices" - "sort" "strings" "time" @@ -727,8 +727,8 @@ func framesAtDepthFiltered(frames []tuiFrame, depth int, include map[int]bool) [ indices = append(indices, idx) } } - sort.Slice(indices, func(i, j int) bool { - return frames[indices[i]].Col < frames[indices[j]].Col + slices.SortFunc(indices, func(a, b int) int { + return cmp.Compare(frames[a].Col, frames[b].Col) }) return indices } @@ -878,19 +878,19 @@ func (m Model) visibleTraversalOrder() []int { } indices = append(indices, idx) } - sort.Slice(indices, func(i, j int) bool { - left := m.frames[indices[i]] - right := m.frames[indices[j]] + slices.SortFunc(indices, func(a, b int) int { + left := m.frames[a] + right := m.frames[b] if left.Depth != right.Depth { - return left.Depth < right.Depth + return cmp.Compare(left.Depth, right.Depth) } if left.Col != right.Col { - return left.Col < right.Col + return cmp.Compare(left.Col, right.Col) } if left.Row != right.Row { - return left.Row < right.Row + return cmp.Compare(left.Row, right.Row) } - return indices[i] < indices[j] + return cmp.Compare(a, b) }) return indices } diff --git a/internal/tui/flamegraph/renderer.go b/internal/tui/flamegraph/renderer.go index f9f6a89..12e5f8e 100644 --- a/internal/tui/flamegraph/renderer.go +++ b/internal/tui/flamegraph/renderer.go @@ -1,11 +1,12 @@ package flamegraph import ( + "cmp" "fmt" "hash/fnv" "image/color" "math" - "sort" + "slices" "strings" "unicode/utf8" @@ -129,11 +130,11 @@ func allocateChildWidths(children []*snapshotNode, parentTotal uint64, span int) // If proportional rounding culled every child, surface top contributors so // the user can still navigate beyond the root frame. if used == 0 { - sort.Slice(items, func(i, j int) bool { - if items[i].total == items[j].total { - return items[i].idx < items[j].idx + slices.SortFunc(items, func(a, b childWidth) int { + if a.total != b.total { + return cmp.Compare(b.total, a.total) } - return items[i].total > items[j].total + return cmp.Compare(a.idx, b.idx) }) visible := min(span, len(items)) for i := 0; i < visible; i++ { @@ -334,8 +335,8 @@ func buildRenderRows(frames []tuiFrame, width, rowOffset, maxRow, barHeight, ava rows := make([]string, 0, (maxRow-rowOffset+1)*barHeight) for row := maxRow; row >= rowOffset; row-- { framesAtRow := rowsByDepth[row] - sort.Slice(framesAtRow, func(i, j int) bool { - return framesAtRow[i].frame.Col < framesAtRow[j].frame.Col + slices.SortFunc(framesAtRow, func(a, b indexedFrame) int { + return cmp.Compare(a.frame.Col, b.frame.Col) }) for repeat := 0; repeat < barHeight; repeat++ { showLabels := repeat == barHeight/2 @@ -680,8 +681,8 @@ func compactMatchRoots(frames []tuiFrame, matchSet map[int]bool) []matchRoot { total: frames[idx].Total, }) } - sort.Slice(roots, func(i, j int) bool { - return len(roots[i].path) < len(roots[j].path) + slices.SortFunc(roots, func(a, b matchRoot) int { + return cmp.Compare(len(a.path), len(b.path)) }) merged := make([]matchRoot, 0, len(roots)) for _, candidate := range roots { |
