1616///
1717/// It also enables recursive types by introducing a "box" into the cycle, which
1818/// allows the owning type to have a finite size.
19- @_spi ( Generated)
20- public struct CopyOnWriteBox < Wrapped> {
19+ @_spi ( Generated) public struct CopyOnWriteBox < Wrapped> {
2120
2221 /// The reference type storage for the box.
23- @usableFromInline
24- internal final class Storage {
22+ @usableFromInline internal final class Storage {
2523
2624 /// The stored value.
27- @usableFromInline
28- var value : Wrapped
25+ @usableFromInline var value : Wrapped
2926
3027 /// Creates a new storage with the provided initial value.
3128 /// - Parameter value: The initial value to store in the box.
32- @inlinable
33- init ( value: Wrapped ) {
34- self . value = value
35- }
29+ @inlinable init ( value: Wrapped ) { self . value = value }
3630 }
3731
3832 /// The internal storage of the box.
39- @usableFromInline
40- internal var storage : Storage
33+ @usableFromInline internal var storage : Storage
4134
4235 /// Creates a new box.
4336 /// - Parameter value: The value to store in the box.
44- @inlinable
45- public init ( value: Wrapped ) {
46- self . storage = . init( value: value)
47- }
37+ @inlinable public init ( value: Wrapped ) { self . storage = . init( value: value) }
4838
4939 /// The stored value whose accessors enforce copy-on-write semantics.
50- @inlinable
51- public var value : Wrapped {
52- get {
53- storage. value
54- }
40+ @inlinable public var value : Wrapped {
41+ get { storage. value }
5542 _modify {
56- if !isKnownUniquelyReferenced( & storage) {
57- storage = Storage ( value: storage. value)
58- }
43+ if !isKnownUniquelyReferenced( & storage) { storage = Storage ( value: storage. value) }
5944 yield & storage. value
6045 }
6146 }
@@ -73,10 +58,7 @@ extension CopyOnWriteBox: Encodable where Wrapped: Encodable {
7358 ///
7459 /// - Parameter encoder: The encoder to write data to.
7560 /// - Throws: On an encoding error.
76- @inlinable
77- public func encode( to encoder: any Encoder ) throws {
78- try value. encode ( to: encoder)
79- }
61+ @inlinable public func encode( to encoder: any Encoder ) throws { try value. encode ( to: encoder) }
8062}
8163
8264extension CopyOnWriteBox : Decodable where Wrapped: Decodable {
@@ -88,8 +70,7 @@ extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
8870 ///
8971 /// - Parameter decoder: The decoder to read data from.
9072 /// - Throws: On a decoding error.
91- @inlinable
92- public init ( from decoder: any Decoder ) throws {
73+ @inlinable public init ( from decoder: any Decoder ) throws {
9374 let value = try Wrapped ( from: decoder)
9475 self . init ( value: value)
9576 }
@@ -106,11 +87,7 @@ extension CopyOnWriteBox: Equatable where Wrapped: Equatable {
10687 /// - lhs: A value to compare.
10788 /// - rhs: Another value to compare.
10889 /// - Returns: A Boolean value indicating whether the values are equal.
109- @inlinable
110- public static func == (
111- lhs: CopyOnWriteBox < Wrapped > ,
112- rhs: CopyOnWriteBox < Wrapped >
113- ) -> Bool {
90+ @inlinable public static func == ( lhs: CopyOnWriteBox < Wrapped > , rhs: CopyOnWriteBox < Wrapped > ) -> Bool {
11491 lhs. value == rhs. value
11592 }
11693}
@@ -132,10 +109,7 @@ extension CopyOnWriteBox: Hashable where Wrapped: Hashable {
132109 ///
133110 /// - Parameter hasher: The hasher to use when combining the components
134111 /// of this instance.
135- @inlinable
136- public func hash( into hasher: inout Hasher ) {
137- hasher. combine ( value)
138- }
112+ @inlinable public func hash( into hasher: inout Hasher ) { hasher. combine ( value) }
139113}
140114
141115extension CopyOnWriteBox : CustomStringConvertible where Wrapped: CustomStringConvertible {
@@ -163,10 +137,7 @@ extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringCon
163137 ///
164138 /// The conversion of `p` to a string in the assignment to `s` uses the
165139 /// `Point` type's `description` property.
166- @inlinable
167- public var description : String {
168- value. description
169- }
140+ @inlinable public var description : String { value. description }
170141}
171142
172143extension CopyOnWriteBox : CustomDebugStringConvertible where Wrapped: CustomDebugStringConvertible {
@@ -194,10 +165,7 @@ extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebu
194165 ///
195166 /// The conversion of `p` to a string in the assignment to `s` uses the
196167 /// `Point` type's `debugDescription` property.
197- @inlinable
198- public var debugDescription : String {
199- value. debugDescription
200- }
168+ @inlinable public var debugDescription : String { value. debugDescription }
201169}
202170
203171extension CopyOnWriteBox : @unchecked Sendable where Wrapped: Sendable { }
0 commit comments