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 | |
| parent | b421b2232351049277ee4ad5b31367bb2b6779bb (diff) | |
cleanup
Diffstat (limited to 'internal/tui')
| -rw-r--r-- | internal/tui/dashboard/bubbles.go | 19 | ||||
| -rw-r--r-- | internal/tui/dashboard/files.go | 10 | ||||
| -rw-r--r-- | internal/tui/dashboard/icicle.go | 15 | ||||
| -rw-r--r-- | internal/tui/dashboard/treemap.go | 27 | ||||
| -rw-r--r-- | internal/tui/flamegraph/model.go | 20 | ||||
| -rw-r--r-- | internal/tui/flamegraph/renderer.go | 19 | ||||
| -rw-r--r-- | internal/tui/pidpicker/proclist.go | 19 |
7 files changed, 67 insertions, 62 deletions
diff --git a/internal/tui/dashboard/bubbles.go b/internal/tui/dashboard/bubbles.go index e6e2909..f50eba8 100644 --- a/internal/tui/dashboard/bubbles.go +++ b/internal/tui/dashboard/bubbles.go @@ -1,11 +1,12 @@ package dashboard import ( + "cmp" "fmt" "hash/fnv" "image/color" "math" - "sort" + "slices" "strings" "unicode/utf8" @@ -422,8 +423,8 @@ func (c *bubbleChart) renderBubblesToGrid(grid [][]bubbleCell, width, height int for idx := range c.nodes { order = append(order, idx) } - sort.Slice(order, func(i, j int) bool { - return c.nodes[order[i]].radius < c.nodes[order[j]].radius + slices.SortFunc(order, func(a, b int) int { + return cmp.Compare(c.nodes[a].radius, c.nodes[b].radius) }) if c.selected >= 0 && c.selected < len(c.nodes) { filtered := order[:0] @@ -641,13 +642,13 @@ func buildBubbleTargets(data []bubbleDatum, metric bubbleMetric, width, height i if len(filtered) == 0 { return nil } - sort.Slice(filtered, func(i, j int) bool { - vi := bubbleValue(filtered[i], metric) - vj := bubbleValue(filtered[j], metric) - if vi != vj { - return vi > vj + slices.SortFunc(filtered, func(a, b bubbleDatum) int { + va := bubbleValue(a, metric) + vb := bubbleValue(b, metric) + if va != vb { + return cmp.Compare(vb, va) } - return filtered[i].Label < filtered[j].Label + return cmp.Compare(a.Label, b.Label) }) if len(filtered) > bubbleMaxItems { filtered = filtered[:bubbleMaxItems] diff --git a/internal/tui/dashboard/files.go b/internal/tui/dashboard/files.go index f24c87c..df850ab 100644 --- a/internal/tui/dashboard/files.go +++ b/internal/tui/dashboard/files.go @@ -1,9 +1,9 @@ package dashboard import ( + "cmp" "path/filepath" "slices" - "sort" "strconv" "ior/internal/statsengine" @@ -425,11 +425,11 @@ func aggregateFilesByDir(files []statsengine.FileSnapshot) []DirSnapshot { out = append(out, s) } - sort.Slice(out, func(i, j int) bool { - if out[i].Accesses != out[j].Accesses { - return out[i].Accesses > out[j].Accesses + slices.SortFunc(out, func(a, b DirSnapshot) int { + if a.Accesses != b.Accesses { + return cmp.Compare(b.Accesses, a.Accesses) } - return out[i].Dir < out[j].Dir + return cmp.Compare(a.Dir, b.Dir) }) return out } diff --git a/internal/tui/dashboard/icicle.go b/internal/tui/dashboard/icicle.go index 92c4834..768783b 100644 --- a/internal/tui/dashboard/icicle.go +++ b/internal/tui/dashboard/icicle.go @@ -1,10 +1,11 @@ package dashboard import ( + "cmp" "fmt" "math" "path/filepath" - "sort" + "slices" "strings" "ior/internal/statsengine" @@ -169,13 +170,13 @@ func sortedIcicleChildren(node *icicleNode, metric bubbleMetric) []*icicleNode { for _, child := range node.children { out = append(out, child) } - sort.Slice(out, func(i, j int) bool { - vi := icicleValue(out[i], metric) - vj := icicleValue(out[j], metric) - if vi != vj { - return vi > vj + slices.SortFunc(out, func(a, b *icicleNode) int { + va := icicleValue(a, metric) + vb := icicleValue(b, metric) + if va != vb { + return cmp.Compare(vb, va) } - return out[i].name < out[j].name + return cmp.Compare(a.name, b.name) }) return out } diff --git a/internal/tui/dashboard/treemap.go b/internal/tui/dashboard/treemap.go index 7193952..dd62d13 100644 --- a/internal/tui/dashboard/treemap.go +++ b/internal/tui/dashboard/treemap.go @@ -1,10 +1,11 @@ package dashboard import ( + "cmp" "fmt" "image/color" "math" - "sort" + "slices" "strings" "unicode/utf8" @@ -131,11 +132,11 @@ func buildSyscallTreemapItems(snap *statsengine.Snapshot, metric bubbleMetric) [ if len(items) == 0 { return nil } - sort.Slice(items, func(i, j int) bool { - if items[i].Value != items[j].Value { - return items[i].Value > items[j].Value + slices.SortFunc(items, func(a, b syscallTreemapItem) int { + if a.Value != b.Value { + return cmp.Compare(b.Value, a.Value) } - return items[i].Name < items[j].Name + return cmp.Compare(a.Name, b.Name) }) if len(items) > maxSyscallTreemapItems { items = items[:maxSyscallTreemapItems] @@ -174,11 +175,11 @@ func buildFilesTreemapItems(snap *statsengine.Snapshot, metric bubbleMetric) []s if len(items) == 0 { return nil } - sort.Slice(items, func(i, j int) bool { - if items[i].Value != items[j].Value { - return items[i].Value > items[j].Value + slices.SortFunc(items, func(a, b syscallTreemapItem) int { + if a.Value != b.Value { + return cmp.Compare(b.Value, a.Value) } - return items[i].Name < items[j].Name + return cmp.Compare(a.Name, b.Name) }) if len(items) > maxSyscallTreemapItems { items = items[:maxSyscallTreemapItems] @@ -217,11 +218,11 @@ func buildProcessesTreemapItems(snap *statsengine.Snapshot, metric bubbleMetric) if len(items) == 0 { return nil } - sort.Slice(items, func(i, j int) bool { - if items[i].Value != items[j].Value { - return items[i].Value > items[j].Value + slices.SortFunc(items, func(a, b syscallTreemapItem) int { + if a.Value != b.Value { + return cmp.Compare(b.Value, a.Value) } - return items[i].Name < items[j].Name + return cmp.Compare(a.Name, b.Name) }) if len(items) > maxSyscallTreemapItems { items = items[:maxSyscallTreemapItems] 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 { diff --git a/internal/tui/pidpicker/proclist.go b/internal/tui/pidpicker/proclist.go index 20e580d..73ff209 100644 --- a/internal/tui/pidpicker/proclist.go +++ b/internal/tui/pidpicker/proclist.go @@ -2,11 +2,12 @@ package pidpicker import ( "bytes" + "cmp" "fmt" "io/fs" "os" "path/filepath" - "sort" + "slices" "strconv" "strings" "sync" @@ -50,8 +51,8 @@ func scanProcessesFrom(procRoot string) ([]ProcessInfo, error) { processes = append(processes, process) } - sort.Slice(processes, func(i, j int) bool { - return processes[i].Pid < processes[j].Pid + slices.SortFunc(processes, func(a, b ProcessInfo) int { + return cmp.Compare(a.Pid, b.Pid) }) return processes, nil } @@ -145,8 +146,8 @@ func scanThreadsFrom(procRoot string, pid int) ([]ProcessInfo, error) { threads = append(threads, thread) } - sort.Slice(threads, func(i, j int) bool { - return threads[i].Pid < threads[j].Pid + slices.SortFunc(threads, func(a, b ProcessInfo) int { + return cmp.Compare(a.Pid, b.Pid) }) return threads, nil } @@ -209,11 +210,11 @@ func scanAllThreadsFrom(procRoot string) ([]ProcessInfo, error) { } wg.Wait() - sort.Slice(threads, func(i, j int) bool { - if threads[i].Pid == threads[j].Pid { - return threads[i].ParentPID < threads[j].ParentPID + slices.SortFunc(threads, func(a, b ProcessInfo) int { + if a.Pid != b.Pid { + return cmp.Compare(a.Pid, b.Pid) } - return threads[i].Pid < threads[j].Pid + return cmp.Compare(a.ParentPID, b.ParentPID) }) return threads, nil } |
