@@ -363,34 +363,19 @@ extension ProgressManager {
363363 }
364364
365365 internal func getUpdatedThroughput( ) -> [ UInt64 ] {
366+ // Collect information from state
367+ let updateInfo = state. withLock { state in
368+ state. getThroughputUpdateInfo ( )
369+ }
370+
371+ // Get updated summary for each dirty child
372+ let updatedSummaries = updateInfo. dirtyChildren. map { ( index, child) in
373+ State . ThroughputUpdate ( index: index, updatedSummary: child. getUpdatedThroughput ( ) )
374+ }
375+
376+ // Consolidate updated values
366377 return state. withLock { state in
367- // Get self's throughput as part of summary
368- var value = ProgressManager . Properties. Throughput. defaultSummary
369- ProgressManager . Properties. Throughput. reduce ( into: & value, value: state. throughput)
370-
371- guard !state. children. isEmpty else {
372- return value
373- }
374-
375- for (idx, childState) in state. children. enumerated ( ) {
376- if childState. throughput. isDirty {
377- // Update dirty path
378- if let child = childState. child {
379- let updatedSummary = child. getUpdatedThroughput ( )
380- let newThroughputState = PropertyStateThroughput ( value: updatedSummary, isDirty: false )
381- state. children [ idx] . throughput = newThroughputState
382- value = ProgressManager . Properties. Throughput. merge ( value, updatedSummary)
383- }
384- } else {
385- if let _ = childState. child {
386- // Merge non-dirty, updated value
387- value = ProgressManager . Properties. Throughput. merge ( value, childState. throughput. value)
388- } else {
389- value = ProgressManager . Properties. Throughput. finalSummary ( value, childState. throughput. value)
390- }
391- }
392- }
393- return value
378+ state. getUpdatedThroughput ( updateInfo, updatedSummaries)
394379 }
395380 }
396381
@@ -518,88 +503,77 @@ extension ProgressManager {
518503
519504 internal func markChildDirty( property: MetatypeWrapper < Int , Int > , at position: Int ) {
520505 let parents = state. withLock { state in
521- state. children [ position] . childPropertiesInt [ property] ? . isDirty = true
522- return state. parents
506+ state. markChildDirty ( property: property, at: position)
523507 }
524508 markSelfDirty ( property: property, parents: parents)
525509 }
526510
527511 internal func markChildDirty( property: MetatypeWrapper < Double , Double > , at position: Int ) {
528512 let parents = state. withLock { state in
529- state. children [ position] . childPropertiesDouble [ property] ? . isDirty = true
530- return state. parents
513+ state. markChildDirty ( property: property, at: position)
531514 }
532515 markSelfDirty ( property: property, parents: parents)
533516 }
534517
535518 internal func markChildDirty( property: MetatypeWrapper < String ? , [ String ? ] > , at position: Int ) {
536519 let parents = state. withLock { state in
537- state. children [ position] . childPropertiesString [ property] ? . isDirty = true
538- return state. parents
520+ state. markChildDirty ( property: property, at: position)
539521 }
540522 markSelfDirty ( property: property, parents: parents)
541523 }
542524
543525 internal func markChildDirty( property: MetatypeWrapper < URL ? , [ URL ? ] > , at position: Int ) {
544526 let parents = state. withLock { state in
545- state. children [ position] . childPropertiesURL [ property] ? . isDirty = true
546- return state. parents
527+ state. markChildDirty ( property: property, at: position)
547528 }
548529 markSelfDirty ( property: property, parents: parents)
549530 }
550531
551532 internal func markChildDirty( property: MetatypeWrapper < UInt64 , [ UInt64 ] > , at position: Int ) {
552533 let parents = state. withLock { state in
553- state. children [ position] . childPropertiesUInt64 [ property] ? . isDirty = true
554- return state. parents
534+ state. markChildDirty ( property: property, at: position)
555535 }
556536 markSelfDirty ( property: property, parents: parents)
557537 }
558538
559539 internal func markChildDirty( property: ProgressManager . Properties . TotalFileCount . Type , at position: Int ) {
560540 let parents = state. withLock { state in
561- state. children [ position] . totalFileCount. isDirty = true
562- return state. parents
541+ state. markChildDirty ( property: property, at: position)
563542 }
564543 markSelfDirty ( property: property, parents: parents)
565544 }
566545
567546 internal func markChildDirty( property: ProgressManager . Properties . CompletedFileCount . Type , at position: Int ) {
568547 let parents = state. withLock { state in
569- state. children [ position] . completedFileCount. isDirty = true
570- return state. parents
548+ state. markChildDirty ( property: property, at: position)
571549 }
572550 markSelfDirty ( property: property, parents: parents)
573551 }
574552
575553 internal func markChildDirty( property: ProgressManager . Properties . TotalByteCount . Type , at position: Int ) {
576554 let parents = state. withLock { state in
577- state. children [ position] . totalByteCount. isDirty = true
578- return state. parents
555+ state. markChildDirty ( property: property, at: position)
579556 }
580557 markSelfDirty ( property: property, parents: parents)
581558 }
582559
583560 internal func markChildDirty( property: ProgressManager . Properties . CompletedByteCount . Type , at position: Int ) {
584561 let parents = state. withLock { state in
585- state. children [ position] . completedByteCount. isDirty = true
586- return state. parents
562+ state. markChildDirty ( property: property, at: position)
587563 }
588564 markSelfDirty ( property: property, parents: parents)
589565 }
590566
591567 internal func markChildDirty( property: ProgressManager . Properties . Throughput . Type , at position: Int ) {
592568 let parents = state. withLock { state in
593- state. children [ position] . throughput. isDirty = true
594- return state. parents
569+ state. markChildDirty ( property: property, at: position)
595570 }
596571 markSelfDirty ( property: property, parents: parents)
597572 }
598573
599574 internal func markChildDirty( property: ProgressManager . Properties . EstimatedTimeRemaining . Type , at position: Int ) {
600575 let parents = state. withLock { state in
601- state. children [ position] . estimatedTimeRemaining. isDirty = true
602- return state. parents
576+ state. markChildDirty ( property: property, at: position)
603577 }
604578 markSelfDirty ( property: property, parents: parents)
605579 }
0 commit comments