@@ -95,18 +95,19 @@ public class ManagedBuffer<Header, Element>
95
95
: ManagedProtoBuffer < Header , Element > {
96
96
97
97
/// Create a new instance of the most-derived class, calling
98
- /// `initialHeader ` on the partially-constructed object to
99
- /// generate an initial `Header`.
98
+ /// `factory ` on the partially-constructed object to generate
99
+ /// an initial `Header`.
100
100
public final class func create(
101
101
minimumCapacity: Int ,
102
- initialHeader: @noescape ( ManagedProtoBuffer < Header , Element > ) throws -> Header
102
+ makingHeaderWith factory: (
103
+ ManagedProtoBuffer < Header , Element > ) throws -> Header
103
104
) rethrows -> ManagedBuffer < Header , Element > {
104
105
105
106
let p = try ManagedBufferPointer < Header , Element > (
106
107
bufferClass: self ,
107
108
minimumCapacity: minimumCapacity,
108
- initialHeader : { buffer, _ in
109
- try initialHeader (
109
+ makingHeaderWith : { buffer, _ in
110
+ try factory (
110
111
unsafeDowncast ( buffer, to: ManagedProtoBuffer< Header, Element> . self ) )
111
112
} )
112
113
@@ -115,14 +116,18 @@ public class ManagedBuffer<Header, Element>
115
116
116
117
/// Destroy the stored Header.
117
118
deinit {
118
- ManagedBufferPointer ( self ) . withUnsafeMutablePointerToHeader { $0. deinitialize ( ) }
119
+ ManagedBufferPointer ( self ) . withUnsafeMutablePointerToHeader {
120
+ $0. deinitialize ( )
121
+ }
119
122
}
120
123
121
124
/// The stored `Header` instance.
122
125
public final var header : Header {
123
126
addressWithNativeOwner {
124
127
return (
125
- ManagedBufferPointer ( self ) . withUnsafeMutablePointerToHeader { UnsafePointer ( $0) } ,
128
+ ManagedBufferPointer ( self ) . withUnsafeMutablePointerToHeader {
129
+ UnsafePointer ( $0)
130
+ } ,
126
131
Builtin . castToNativeObject ( self ) )
127
132
}
128
133
mutableAddressWithNativeOwner {
@@ -177,7 +182,7 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
177
182
/// - parameter bufferClass: The class of the object used for storage.
178
183
/// - parameter minimumCapacity: The minimum number of `Element`s that
179
184
/// must be able to be stored in the new buffer.
180
- /// - parameter initialHeader : A function that produces the initial
185
+ /// - parameter factory : A function that produces the initial
181
186
/// `Header` instance stored in the buffer, given the `buffer`
182
187
/// object and a function that can be called on it to get the actual
183
188
/// number of allocated elements.
@@ -189,14 +194,16 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
189
194
public init (
190
195
bufferClass: AnyClass ,
191
196
minimumCapacity: Int ,
192
- initialHeader: @noescape ( buffer: AnyObject , capacity: @noescape ( AnyObject ) -> Int ) throws -> Header
197
+ makingHeaderWith factory:
198
+ ( buffer: AnyObject , capacity: ( AnyObject ) -> Int ) throws -> Header
193
199
) rethrows {
194
- self = ManagedBufferPointer ( bufferClass: bufferClass, minimumCapacity: minimumCapacity)
200
+ self = ManagedBufferPointer (
201
+ bufferClass: bufferClass, minimumCapacity: minimumCapacity)
195
202
196
203
// initialize the header field
197
204
try withUnsafeMutablePointerToHeader {
198
205
$0. initialize ( to:
199
- try initialHeader (
206
+ try factory (
200
207
buffer: self . buffer,
201
208
capacity: {
202
209
ManagedBufferPointer ( unsafeBufferObject: $0) . capacity
0 commit comments