Adopt typed throws for withUnsafeMutableBufferPointer

This commit is contained in:
Doug Gregor
2024-08-15 14:43:38 -07:00
parent 5c07fd9502
commit 4d037ce6ef
9 changed files with 139 additions and 59 deletions

View File

@@ -1152,6 +1152,21 @@ extension ContiguousArray {
return try _buffer.withUnsafeBufferPointer(body)
}
// Superseded by the typed-throws version of this function, but retained
// for ABI reasons.
@_semantics("array.withUnsafeMutableBufferPointer")
@inlinable // FIXME(inline-always)
@inline(__always) // Performance: This method should get inlined into the
// caller such that we can combine the partial apply with the apply in this
// function saving on allocating a closure context. This becomes unnecessary
// once we allocate noescape closures on the stack.
@_silgen_name("$ss15ContiguousArrayV30withUnsafeMutableBufferPointeryqd__qd__SryxGzKXEKlF")
mutating func __abi_withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R {
return try withUnsafeMutableBufferPointer(body)
}
/// Calls the given closure with a pointer to the array's mutable contiguous
/// storage.
///
@@ -1189,14 +1204,14 @@ extension ContiguousArray {
/// method's execution.
/// - Returns: The return value, if any, of the `body` closure parameter.
@_semantics("array.withUnsafeMutableBufferPointer")
@inlinable // FIXME(inline-always)
@_alwaysEmitIntoClient
@inline(__always) // Performance: This method should get inlined into the
// caller such that we can combine the partial apply with the apply in this
// function saving on allocating a closure context. This becomes unnecessary
// once we allocate noescape closures on the stack.
public mutating func withUnsafeMutableBufferPointer<R>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws -> R
) rethrows -> R {
public mutating func withUnsafeMutableBufferPointer<R, E>(
_ body: (inout UnsafeMutableBufferPointer<Element>) throws(E) -> R
) throws(E) -> R {
_makeMutableAndUnique()
let count = _buffer.mutableCount