perf: small optimizations from profiling

This commit is contained in:
lwouis committed 2026-02-11 21:35:31 +01:00
1 parent 7dec9da401
commit db314c9948
3 files changed
+18 -9

No files matched your search

+16 -3
View File
@@ -570,6 +570,7 @@ class StatusIconsView: FlippedView {
var icons: [Icon] var icons: [Icon]
private let attrs: [NSAttributedString.Key: Any] private let attrs: [NSAttributedString.Key: Any]
private var visibleCount = 0 private var visibleCount = 0
private var tooltipsDirty = true
/// Single-character cell size, cached at init for the layout cache /// Single-character cell size, cached at init for the layout cache
let iconCellSize: NSSize let iconCellSize: NSSize
@@ -585,6 +586,7 @@ class StatusIconsView: FlippedView {
let measure = NSAttributedString(string: Symbols.circledNumber0.rawValue, attributes: attrs) let measure = NSAttributedString(string: Symbols.circledNumber0.rawValue, attributes: attrs)
iconCellSize = measure.size() iconCellSize = measure.size()
super.init(frame: frame) super.init(frame: frame)
addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil))
} }
required init?(coder: NSCoder) { fatalError() } required init?(coder: NSCoder) { fatalError() }
@@ -621,20 +623,31 @@ class StatusIconsView: FlippedView {
let isLTR = App.shared.userInterfaceLayoutDirection == .leftToRight let isLTR = App.shared.userInterfaceLayoutDirection == .leftToRight
assignIfDifferent(&frame.origin.x, isLTR ? edgeInsets + hWidth - indicatorSpace : edgeInsets) assignIfDifferent(&frame.origin.x, isLTR ? edgeInsets + hWidth - indicatorSpace : edgeInsets)
assignIfDifferent(&frame.origin.y, edgeInsets) assignIfDifferent(&frame.origin.y, edgeInsets)
tooltipsDirty = true
needsDisplay = true
}
override func mouseEntered(with event: NSEvent) {
ensureTooltipsInstalled()
}
private func ensureTooltipsInstalled() {
guard tooltipsDirty else { return }
tooltipsDirty = false
removeAllToolTips() removeAllToolTips()
let iconWidth = ThumbnailsView.layoutCache.iconWidth let iconWidth = ThumbnailsView.layoutCache.iconWidth
let iconHeight = ThumbnailsView.layoutCache.iconHeight let iconHeight = ThumbnailsView.layoutCache.iconHeight
let yOffset = ((hHeight - iconHeight) / 2).rounded() let isLTR = App.shared.userInterfaceLayoutDirection == .leftToRight
let yOffset = ((frame.height - iconHeight) / 2).rounded()
var offset = CGFloat(0) var offset = CGFloat(0)
for icon in icons { for icon in icons {
guard icon.visible else { continue } guard icon.visible else { continue }
offset += iconWidth offset += iconWidth
let x = isLTR ? indicatorSpace - offset : offset - iconWidth let x = isLTR ? frame.width - offset : offset - iconWidth
if let tooltip = icon.tooltip { if let tooltip = icon.tooltip {
_ = addToolTip(NSRect(x: x, y: yOffset, width: iconWidth, height: iconHeight), owner: tooltip as NSString, userData: nil) _ = addToolTip(NSRect(x: x, y: yOffset, width: iconWidth, height: iconHeight), owner: tooltip as NSString, userData: nil)
} }
} }
needsDisplay = true
} }
override func draw(_ dirtyRect: NSRect) { override func draw(_ dirtyRect: NSRect) {
+1 -1
View File
@@ -62,7 +62,7 @@ class ThumbnailsPanel: NSPanel {
makeKeyAndOrderFront(nil) makeKeyAndOrderFront(nil)
MouseEvents.toggle(true) MouseEvents.toggle(true)
CursorEvents.toggle(true) CursorEvents.toggle(true)
thumbnailsView.scrollView.flashScrollers() DispatchQueue.main.async { self.thumbnailsView.scrollView.flashScrollers() }
} }
static func maxThumbnailsWidth(_ screen: NSScreen = NSScreen.preferred) -> CGFloat { static func maxThumbnailsWidth(_ screen: NSScreen = NSScreen.preferred) -> CGFloat {
+1 -5
View File
@@ -228,11 +228,6 @@ class ThumbnailsView {
} }
scrollView.documentView!.frame.size = NSSize(width: maxX, height: maxY) scrollView.documentView!.frame.size = NSSize(width: maxX, height: maxY)
highlightOverlay.frame = CGRect(origin: .zero, size: scrollView.documentView!.frame.size) highlightOverlay.frame = CGRect(origin: .zero, size: scrollView.documentView!.frame.size)
if let existingTrackingArea = scrollView.trackingAreas.first {
scrollView.removeTrackingArea(existingTrackingArea)
}
scrollView.addTrackingArea(NSTrackingArea(rect: scrollView.bounds,
options: [.mouseMoved, .mouseEnteredAndExited, .activeAlways], owner: scrollView, userInfo: nil))
} }
func centerRows(_ maxX: CGFloat) { func centerRows(_ maxX: CGFloat) {
@@ -309,6 +304,7 @@ class ScrollView: NSScrollView {
scrollerKnobStyle = .light scrollerKnobStyle = .light
horizontalScrollElasticity = .none horizontalScrollElasticity = .none
usesPredominantAxisScrolling = true usesPredominantAxisScrolling = true
addTrackingArea(NSTrackingArea(rect: .zero, options: [.mouseMoved, .mouseEnteredAndExited, .activeAlways, .inVisibleRect], owner: self, userInfo: nil))
observeScrollingEvents() observeScrollingEvents()
} }