Skip to content

Commit 56a1256

Browse files
authored
Remove Data(rawCapacity:initializingWith:) (#2211)
1 parent 1335fd1 commit 56a1256

3 files changed

Lines changed: 4 additions & 36 deletions

File tree

Sources/FoundationEssentials/Data/Data.swift

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -281,38 +281,6 @@ public struct Data : RandomAccessCollection, MutableCollection, RangeReplaceable
281281
_representation = .empty
282282
}
283283

284-
/// Creates a data instance with the specified capacity, and then calls the given
285-
/// closure with an output span covering the instance's uninitialized memory.
286-
///
287-
/// Inside the closure, initialize elements by appending to the `OutputRawSpan`.
288-
/// The `OutputRawSpan` keeps track of the initialized memory, ensuring
289-
/// safety. Its `count` at the end of the closure will become the `count` of
290-
/// the newly-initialized instance of `Data`.
291-
///
292-
/// - Note: While the resulting `Data` may have a capacity larger than the
293-
/// requested amount, the `OutputRawSpan` passed to the closure will cover
294-
/// exactly the number of bytes requested.
295-
///
296-
/// - Parameters:
297-
/// - capacity: The number of bytes to allocate space for in the new `Data`.
298-
/// - initializer: A closure to initialize the allocated memory.
299-
/// - Parameters:
300-
/// - span: An `OutputRawSpan` covering uninitialized memory with
301-
/// space for the specified number of bytes.
302-
@available(macOS, introduced: 10.14.4, deprecated, renamed: "init(capacity:initializingWith:)")
303-
@available(iOS, introduced: 12.2, deprecated, renamed: "init(capacity:initializingWith:)")
304-
@available(watchOS, introduced: 5.2, deprecated, renamed: "init(capacity:initializingWith:)")
305-
@available(tvOS, introduced: 12.2, deprecated, renamed: "init(capacity:initializingWith:)")
306-
@available(visionOS, introduced: 1.0, deprecated, renamed: "init(capacity:initializingWith:)")
307-
@export(implementation)
308-
@_spi(_) // TODO: Remove after no clients are using this
309-
public init<E: Error>(
310-
rawCapacity capacity: Int,
311-
initializingWith initializer: (_ span: inout OutputRawSpan) throws(E) -> Void
312-
) throws(E) {
313-
try self.init(capacity: capacity, initializingWith: initializer)
314-
}
315-
316284
/// Creates a new data with the specified capacity, directly initializing its storage using an output raw span.
317285
///
318286
/// - Parameters:

Sources/FoundationEssentials/Data/Representations/Data+Inline.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ extension Data {
8585
@available(macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2, *)
8686
@export(implementation) @inline(__always)
8787
init<E: Error>(
88-
rawCapacity: Int,
88+
capacity: Int,
8989
initializingWith initializer: (inout OutputRawSpan) throws(E) -> Void
9090
) throws(E) {
9191
self.init()
9292
do throws(E) {
9393
let count = try Swift.withUnsafeMutableBytes(of: &bytes) {
9494
buffer throws(E) in
95-
let prefix = buffer.prefix(rawCapacity)
95+
let prefix = buffer.prefix(capacity)
9696
var output = OutputRawSpan(buffer: prefix, initializedCount: 0)
9797
try initializer(&output)
9898
return output.finalize(for: prefix)
9999
}
100-
assert(count <= rawCapacity)
100+
assert(count <= capacity)
101101
length = UInt8(count)
102102
} catch {
103103
self = .init()

Sources/FoundationEssentials/Data/Representations/Data+LegacyRepresentation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ extension Data {
104104
capacity: Int, _ initializer: (inout OutputRawSpan) throws(E) -> Void
105105
) throws(E) {
106106
if InlineData.canStore(count: capacity) {
107-
let inline = try InlineData(rawCapacity: capacity, initializingWith: initializer)
107+
let inline = try InlineData(capacity: capacity, initializingWith: initializer)
108108
self = (inline.count == 0) ? .empty : .inline(inline)
109109
} else {
110110
let storage = __DataStorage(capacity: capacity)

0 commit comments

Comments
 (0)