perf(menubar): 减少进程表刷新排序并清理闲置代码

This commit is contained in:
2026-11-16 00:06:14 +08:00
parent 97c1bc3b7f
commit 3ee6b45eb4
7 changed files with 43 additions and 73 deletions
+19
View File
@@ -34,6 +34,25 @@ import Foundation
let sorted = ProcessTableProjection.rows([row, high, low, zero], query: "", sorting: [ProcessSort(key: .power, order: direction)], order: [])
precondition(sorted.last?.cpuPower == nil && sorted.first?.cpuPower == (direction == .forward ? 0 : 3))
}
// The selected process can exit while its PID is reused. The replacement
// joins the sorted newcomers, while retained rows keep fresh measurements.
let fresh = ProcessMetrics(id: large.id, name: large.name, path: nil, cpu: 1,
footprintBytes: nil, threads: 2, restricted: false)
let newcomer = ProcessMetrics(id: .init(pid: 44, seconds: 10, microseconds: 0),
name: "new", path: nil, cpu: 2, footprintBytes: nil,
threads: 1, restricted: false)
let held = ProcessTableProjection.rows([replacement, newcomer, fresh], query: "",
sorting: [ProcessSort(key: .cpu)], order: [id, large.id])
precondition(held.map(\.id) == [large.id, newcomer.id, reused])
precondition(held.first?.threads == 2 && held.first?.footprintBytes == nil)
let filteredHeld = ProcessTableProjection.rows([row, fresh], query: "large", sorting: [], order: [id, large.id])
precondition(filteredHeld.map(\.id) == [large.id])
let nearlyMax = ProcessMetrics(id: id, name: "a", path: nil, cpu: nil,
footprintBytes: UInt64.max - 1, threads: nil, restricted: false)
let max = ProcessMetrics(id: large.id, name: "z", path: nil, cpu: nil,
footprintBytes: UInt64.max, threads: nil, restricted: false)
precondition(ProcessSort(key: .memory).compare(nearlyMax, max) == .orderedDescending)
print("PASS: filtered/live selection, absent selection/snapshot, failed enumeration, actual exit and PID reuse")
}
}