Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/Cacheout/ViewModels/CacheoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class CacheoutViewModel: ObservableObject {
}

var selectedSize: Int64 {
selectedResults.reduce(0) { $0 + $1.sizeBytes }
// ⚑ Bolt Optimization: Chain .lazy.filter before .reduce to prevent intermediate array allocations
scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes }
}

var formattedSelectedSize: String {
Expand All @@ -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:) to short-circuit evaluation instead of checking .isEmpty on an eagerly filtered array or reducing sizes
scanResults.contains(where: \.isSelected) || nodeModulesItems.contains(where: \.isSelected)
}

// MARK: - Node Modules computed properties

Expand Down
Loading