@@ -301,6 +301,18 @@ extension ProgressManager {
301
301
}
302
302
303
303
// MARK: Clean up dirty paths
304
+ internal struct IntSummaryUpdateInfo {
305
+ let currentSummary : Int
306
+ let dirtyChildren : [ ( index: Int , manager: ProgressManager ) ]
307
+ let nonDirtySummaries : [ ( index: Int , summary: Int , isAlive: Bool ) ]
308
+ let property : MetatypeWrapper < Int , Int >
309
+ }
310
+
311
+ internal struct IntSummaryUpdate {
312
+ let index : Int
313
+ let updatedSummary : Int
314
+ }
315
+
304
316
internal struct FileCountUpdateInfo {
305
317
let currentSummary : Int
306
318
let dirtyChildren : [ ( index: Int , manager: ProgressManager ) ]
@@ -347,6 +359,69 @@ extension ProgressManager {
347
359
let updatedSummary : Duration
348
360
}
349
361
362
+ internal mutating func getIntSummaryUpdateInfo( property: MetatypeWrapper < Int , Int > ) -> IntSummaryUpdateInfo {
363
+ var currentSummary : Int = property. defaultSummary
364
+ property. reduce ( & currentSummary, propertiesInt [ property] ?? property. defaultValue)
365
+
366
+ guard !children. isEmpty else {
367
+ return IntSummaryUpdateInfo (
368
+ currentSummary: currentSummary,
369
+ dirtyChildren: [ ] ,
370
+ nonDirtySummaries: [ ] ,
371
+ property: property
372
+ )
373
+ }
374
+
375
+ var dirtyChildren : [ ( index: Int , manager: ProgressManager ) ] = [ ]
376
+ var nonDirtySummaries : [ ( index: Int , summary: Int , isAlive: Bool ) ] = [ ]
377
+
378
+ for (idx, childState) in children. enumerated ( ) {
379
+ if let childPropertyState = childState. childPropertiesInt [ property] {
380
+ if childPropertyState. isDirty {
381
+ if let child = childState. child {
382
+ dirtyChildren. append ( ( idx, child) )
383
+ }
384
+ } else {
385
+ let isAlive = childState. child != nil
386
+ nonDirtySummaries. append ( ( idx, childPropertyState. value, isAlive) )
387
+ }
388
+ } else {
389
+ // Property doesn't exist yet in child - need to fetch it
390
+ if let child = childState. child {
391
+ dirtyChildren. append ( ( idx, child) )
392
+ }
393
+ }
394
+ }
395
+
396
+ return IntSummaryUpdateInfo (
397
+ currentSummary: currentSummary,
398
+ dirtyChildren: dirtyChildren,
399
+ nonDirtySummaries: nonDirtySummaries,
400
+ property: property
401
+ )
402
+ }
403
+
404
+ internal mutating func updateIntSummary( _ updateInfo: IntSummaryUpdateInfo , _ childUpdates: [ IntSummaryUpdate ] ) -> Int {
405
+ var value = updateInfo. currentSummary
406
+
407
+ // Apply updates from children that were dirty
408
+ for update in childUpdates {
409
+ children [ update. index] . childPropertiesInt [ updateInfo. property] = PropertyStateInt ( value: update. updatedSummary, isDirty: false )
410
+ value = updateInfo. property. merge ( value, update. updatedSummary)
411
+ }
412
+
413
+ // Apply values from non-dirty children
414
+ for (_, childSummary, isAlive) in updateInfo. nonDirtySummaries {
415
+ if isAlive {
416
+ value = updateInfo. property. merge ( value, childSummary)
417
+ } else {
418
+ value = updateInfo. property. finalSummary ( value, childSummary)
419
+ }
420
+ }
421
+
422
+ return value
423
+ }
424
+
350
425
internal mutating func getFileCountUpdateInfo( type: CountType ) -> FileCountUpdateInfo {
351
426
let currentSummary : Int
352
427
var dirtyChildren : [ ( index: Int , manager: ProgressManager ) ] = [ ]
0 commit comments