@@ -22,15 +22,16 @@ open class Operation: CustomStringConvertible, CustomDebugStringConvertible {
2222 @Synchronized
2323 internal final var state : State = . created
2424
25+ // queue, observers and conditions are write-protected using `state`.
2526 internal private( set) final var queue : DispatchQueue ?
2627
2728 /// The list of observers of this operation.
28- public private( set) final var observers : [ OperationObserver ] = [ ]
29+ public private( set) final var observers = Array < OperationObserver > ( )
2930 /// The list of conditions of this operation.
30- public private( set) final var conditions : [ OperationCondition ] = [ ]
31+ public private( set) final var conditions = Array < OperationCondition > ( )
3132
3233 @Synchronized
33- private final var _dependencies : ContiguousArray < Operation > = [ ]
34+ private final var _dependencies = ContiguousArray < Operation > ( )
3435 /// The list of dependencies of this operation.
3536 public final var dependencies : ContiguousArray < Operation > { _dependencies }
3637
@@ -39,7 +40,9 @@ open class Operation: CustomStringConvertible, CustomDebugStringConvertible {
3940 private let dependenciesGroup = DispatchGroup ( )
4041
4142 /// The list of errors this operation encountered.
42- public private( set) final var errors : [ Error ] = [ ]
43+ @Synchronized
44+ private final var _errors = Array < Error > ( )
45+ public final var errors : Array < Error > { _errors }
4346
4447 // MARK: - State Accessors
4548 /// Whether or not this operation was cancelled.
@@ -117,7 +120,7 @@ open class Operation: CustomStringConvertible, CustomDebugStringConvertible {
117120 /// Aggregates a collection of errors into the list of errors of this operation.
118121 /// - Parameter newErrors: The collections of errors to aggregate.
119122 public final func aggregate< Errors> ( errors newErrors: Errors ) where Errors: Collection , Errors. Element: Error {
120- errors . append ( contentsOf: newErrors. lazy. map { $0 } )
123+ __errors . withValue { $0 . append ( contentsOf: newErrors. lazy. map { $0 } ) }
121124 }
122125
123126 /// Aggregates a variadic list of errors into the list of errors of this operation.
@@ -153,11 +156,7 @@ open class Operation: CustomStringConvertible, CustomDebugStringConvertible {
153156 return false
154157 }
155158 guard !isCancelled else { return }
156- if let group = group {
157- queue. async ( group: group, execute: run)
158- } else {
159- queue. async ( execute: run)
160- }
159+ queue. async ( group: group, execute: run)
161160 }
162161
163162 private final func run( ) {
0 commit comments