From 99922d4c510a9dc04b32f65158a9da0f9204e85d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 28 May 2026 04:02:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20computed=20prope?= =?UTF-8?q?rties=20to=20avoid=20intermediate=20array=20allocations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Use `.lazy.filter` before `.reduce` in `selectedSize` to prevent O(N) intermediate array allocations. - Replace `!selectedResults.isEmpty` with `scanResults.contains(where:)` in `hasSelection` to short-circuit evaluation. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- Sources/Cacheout/ViewModels/CacheoutViewModel.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift index 27de41a..9d8fb43 100644 --- a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift +++ b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift @@ -106,7 +106,8 @@ class CacheoutViewModel: ObservableObject { } var selectedSize: Int64 { - selectedResults.reduce(0) { $0 + $1.sizeBytes } + // ⚡ Bolt Optimization: Use .lazy.filter before .reduce to prevent O(N) intermediate array allocations + scanResults.lazy.filter { $0.isSelected }.reduce(0) { $0 + $1.sizeBytes } } var formattedSelectedSize: String { @@ -118,7 +119,10 @@ class CacheoutViewModel: ObservableObject { } var hasResults: Bool { !scanResults.isEmpty || !nodeModulesItems.isEmpty } - var hasSelection: Bool { !selectedResults.isEmpty || selectedNodeModulesSize > 0 } + var hasSelection: Bool { + // ⚡ Bolt Optimization: Use .contains(where:) instead of checking .isEmpty on an eagerly filtered array to short-circuit evaluation + scanResults.contains(where: { $0.isSelected }) || selectedNodeModulesSize > 0 + } // MARK: - Node Modules computed properties