From 7283e86d42d55d84fbeae02a98e9b252c83f6c56 Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Wed, 12 Aug 2026 14:39:08 +0200 Subject: make cell more efficient by diffing them by rawValue + highlight --- Sources/bar/Models/Cell.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Sources/bar/Models/Cell.swift b/Sources/bar/Models/Cell.swift index 9e0d46f..48798ba 100644 --- a/Sources/bar/Models/Cell.swift +++ b/Sources/bar/Models/Cell.swift @@ -1,4 +1,3 @@ -import Foundation import RegexBuilder import SwiftUI @@ -30,7 +29,11 @@ import SwiftUI /// window manager workspaces and which one is active. struct Cell: RawRepresentable, Identifiable { /// Stable identity for SwiftUI diffing. - let id = UUID() + /// + /// The id is constructed by the rawValue + highlight + /// so that SwiftUI redraws the cell only on content + /// change and not every time the cell is computed. + let id: String /// The represented text content. let rawValue: String @@ -61,6 +64,7 @@ struct Cell: RawRepresentable, Identifiable { guard let match = rawValue.firstMatch(of: pattern) else { self.rawValue = rawValue self.highlight = 0 + self.id = "\(rawValue):0" return } @@ -71,5 +75,6 @@ struct Cell: RawRepresentable, Identifiable { } self.rawValue = String(match.output.2) + self.id = "\(self.rawValue):\(self.highlight)" } } -- cgit v1.2.3