16
16
///
17
17
/// It also enables recursive types by introducing a "box" into the cycle, which
18
18
/// allows the owning type to have a finite size.
19
- @_spi ( Generated)
20
- public struct CopyOnWriteBox < Wrapped> {
19
+ @_spi ( Generated) public struct CopyOnWriteBox < Wrapped> {
21
20
22
21
/// The reference type storage for the box.
23
- @usableFromInline
24
- internal final class Storage {
22
+ @usableFromInline internal final class Storage {
25
23
26
24
/// The stored value.
27
- @usableFromInline
28
- var value : Wrapped
25
+ @usableFromInline var value : Wrapped
29
26
30
27
/// Creates a new storage with the provided initial value.
31
28
/// - 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 }
36
30
}
37
31
38
32
/// The internal storage of the box.
39
- @usableFromInline
40
- internal var storage : Storage
33
+ @usableFromInline internal var storage : Storage
41
34
42
35
/// Creates a new box.
43
36
/// - 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) }
48
38
49
39
/// 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 }
55
42
_modify {
56
- if !isKnownUniquelyReferenced( & storage) {
57
- storage = Storage ( value: storage. value)
58
- }
43
+ if !isKnownUniquelyReferenced( & storage) { storage = Storage ( value: storage. value) }
59
44
yield & storage. value
60
45
}
61
46
}
@@ -73,10 +58,7 @@ extension CopyOnWriteBox: Encodable where Wrapped: Encodable {
73
58
///
74
59
/// - Parameter encoder: The encoder to write data to.
75
60
/// - 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) }
80
62
}
81
63
82
64
extension CopyOnWriteBox : Decodable where Wrapped: Decodable {
@@ -88,8 +70,7 @@ extension CopyOnWriteBox: Decodable where Wrapped: Decodable {
88
70
///
89
71
/// - Parameter decoder: The decoder to read data from.
90
72
/// - Throws: On a decoding error.
91
- @inlinable
92
- public init ( from decoder: any Decoder ) throws {
73
+ @inlinable public init ( from decoder: any Decoder ) throws {
93
74
let value = try Wrapped ( from: decoder)
94
75
self . init ( value: value)
95
76
}
@@ -106,11 +87,7 @@ extension CopyOnWriteBox: Equatable where Wrapped: Equatable {
106
87
/// - lhs: A value to compare.
107
88
/// - rhs: Another value to compare.
108
89
/// - 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 {
114
91
lhs. value == rhs. value
115
92
}
116
93
}
@@ -132,10 +109,7 @@ extension CopyOnWriteBox: Hashable where Wrapped: Hashable {
132
109
///
133
110
/// - Parameter hasher: The hasher to use when combining the components
134
111
/// 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) }
139
113
}
140
114
141
115
extension CopyOnWriteBox : CustomStringConvertible where Wrapped: CustomStringConvertible {
@@ -163,10 +137,7 @@ extension CopyOnWriteBox: CustomStringConvertible where Wrapped: CustomStringCon
163
137
///
164
138
/// The conversion of `p` to a string in the assignment to `s` uses the
165
139
/// `Point` type's `description` property.
166
- @inlinable
167
- public var description : String {
168
- value. description
169
- }
140
+ @inlinable public var description : String { value. description }
170
141
}
171
142
172
143
extension CopyOnWriteBox : CustomDebugStringConvertible where Wrapped: CustomDebugStringConvertible {
@@ -194,10 +165,7 @@ extension CopyOnWriteBox: CustomDebugStringConvertible where Wrapped: CustomDebu
194
165
///
195
166
/// The conversion of `p` to a string in the assignment to `s` uses the
196
167
/// `Point` type's `debugDescription` property.
197
- @inlinable
198
- public var debugDescription : String {
199
- value. debugDescription
200
- }
168
+ @inlinable public var debugDescription : String { value. debugDescription }
201
169
}
202
170
203
171
extension CopyOnWriteBox : @unchecked Sendable where Wrapped: Sendable { }
0 commit comments