Skip to content

Commit 60f66a6

Browse files
author
Dave Abrahams
committed
initialValue: => makingValueWith factory: (ManagedBuffer)
1 parent dcbfdb5 commit 60f66a6

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

stdlib/public/core/ManagedBuffer.swift

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,19 @@ public class ManagedBuffer<Header, Element>
9595
: ManagedProtoBuffer<Header, Element> {
9696

9797
/// 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`.
100100
public final class func create(
101101
minimumCapacity: Int,
102-
initialHeader: @noescape (ManagedProtoBuffer<Header, Element>) throws -> Header
102+
makingHeaderWith factory: (
103+
ManagedProtoBuffer<Header, Element>) throws -> Header
103104
) rethrows -> ManagedBuffer<Header, Element> {
104105

105106
let p = try ManagedBufferPointer<Header, Element>(
106107
bufferClass: self,
107108
minimumCapacity: minimumCapacity,
108-
initialHeader: { buffer, _ in
109-
try initialHeader(
109+
makingHeaderWith: { buffer, _ in
110+
try factory(
110111
unsafeDowncast(buffer, to: ManagedProtoBuffer<Header, Element>.self))
111112
})
112113

@@ -115,14 +116,18 @@ public class ManagedBuffer<Header, Element>
115116

116117
/// Destroy the stored Header.
117118
deinit {
118-
ManagedBufferPointer(self).withUnsafeMutablePointerToHeader { $0.deinitialize() }
119+
ManagedBufferPointer(self).withUnsafeMutablePointerToHeader {
120+
$0.deinitialize()
121+
}
119122
}
120123

121124
/// The stored `Header` instance.
122125
public final var header: Header {
123126
addressWithNativeOwner {
124127
return (
125-
ManagedBufferPointer(self).withUnsafeMutablePointerToHeader { UnsafePointer($0) },
128+
ManagedBufferPointer(self).withUnsafeMutablePointerToHeader {
129+
UnsafePointer($0)
130+
},
126131
Builtin.castToNativeObject(self))
127132
}
128133
mutableAddressWithNativeOwner {
@@ -177,7 +182,7 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
177182
/// - parameter bufferClass: The class of the object used for storage.
178183
/// - parameter minimumCapacity: The minimum number of `Element`s that
179184
/// 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
181186
/// `Header` instance stored in the buffer, given the `buffer`
182187
/// object and a function that can be called on it to get the actual
183188
/// number of allocated elements.
@@ -189,14 +194,16 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
189194
public init(
190195
bufferClass: AnyClass,
191196
minimumCapacity: Int,
192-
initialHeader: @noescape (buffer: AnyObject, capacity: @noescape (AnyObject) -> Int) throws -> Header
197+
makingHeaderWith factory:
198+
(buffer: AnyObject, capacity: (AnyObject) -> Int) throws -> Header
193199
) rethrows {
194-
self = ManagedBufferPointer(bufferClass: bufferClass, minimumCapacity: minimumCapacity)
200+
self = ManagedBufferPointer(
201+
bufferClass: bufferClass, minimumCapacity: minimumCapacity)
195202

196203
// initialize the header field
197204
try withUnsafeMutablePointerToHeader {
198205
$0.initialize(to:
199-
try initialHeader(
206+
try factory(
200207
buffer: self.buffer,
201208
capacity: {
202209
ManagedBufferPointer(unsafeBufferObject: $0).capacity

0 commit comments

Comments
 (0)