@@ -1565,6 +1565,16 @@ extension Array {
15651565 initializingWith: initializer)
15661566 }
15671567
1568+ // Superseded by the typed-throws version of this function, but retained
1569+ // for ABI reasons.
1570+ @usableFromInline
1571+ @_disfavoredOverload
1572+ func withUnsafeBufferPointer< R> (
1573+ _ body: ( UnsafeBufferPointer < Element > ) throws -> R
1574+ ) rethrows -> R {
1575+ return try _buffer. withUnsafeBufferPointer ( body)
1576+ }
1577+
15681578 /// Calls a closure with a pointer to the array's contiguous storage.
15691579 ///
15701580 /// Often, the optimizer can eliminate bounds checks within an array
@@ -1594,13 +1604,44 @@ extension Array {
15941604 /// for the `withUnsafeBufferPointer(_:)` method. The pointer argument is
15951605 /// valid only for the duration of the method's execution.
15961606 /// - Returns: The return value, if any, of the `body` closure parameter.
1597- @inlinable
1598- public func withUnsafeBufferPointer< R> (
1599- _ body: ( UnsafeBufferPointer < Element > ) throws -> R
1600- ) rethrows -> R {
1607+ @_alwaysEmitIntoClient
1608+ public func withUnsafeBufferPointer< R, E > (
1609+ _ body: ( UnsafeBufferPointer < Element > ) throws ( E ) -> R
1610+ ) throws ( E ) -> R {
16011611 return try _buffer. withUnsafeBufferPointer ( body)
16021612 }
16031613
1614+ // Superseded by the typed-throws version of this function, but retained
1615+ // for ABI reasons.
1616+ @_semantics ( " array.withUnsafeMutableBufferPointer " )
1617+ @_effects ( notEscaping self. value**)
1618+ @usableFromInline
1619+ @inline ( __always)
1620+ @_silgen_name ( " $sSa30withUnsafeMutableBufferPointeryqd__qd__SryxGzKXEKlF " )
1621+ mutating func __abi_withUnsafeMutableBufferPointer< R> (
1622+ _ body: ( inout UnsafeMutableBufferPointer < Element > ) throws -> R
1623+ ) rethrows -> R {
1624+ _makeMutableAndUnique ( )
1625+ let count = _buffer. mutableCount
1626+
1627+ // Create an UnsafeBufferPointer that we can pass to body
1628+ let pointer = _buffer. mutableFirstElementAddress
1629+ var inoutBufferPointer = UnsafeMutableBufferPointer (
1630+ start: pointer, count: count)
1631+
1632+ defer {
1633+ _precondition (
1634+ inoutBufferPointer. baseAddress == pointer &&
1635+ inoutBufferPointer. count == count,
1636+ " Array withUnsafeMutableBufferPointer: replacing the buffer is not allowed " )
1637+ _endMutation ( )
1638+ _fixLifetime ( self )
1639+ }
1640+
1641+ // Invoke the body.
1642+ return try body ( & inoutBufferPointer)
1643+ }
1644+
16041645 /// Calls the given closure with a pointer to the array's mutable contiguous
16051646 /// storage.
16061647 ///
@@ -1639,14 +1680,14 @@ extension Array {
16391680 /// - Returns: The return value, if any, of the `body` closure parameter.
16401681 @_semantics ( " array.withUnsafeMutableBufferPointer " )
16411682 @_effects ( notEscaping self. value**)
1642- @inlinable // FIXME(inline-always)
1683+ @_alwaysEmitIntoClient
16431684 @inline ( __always) // Performance: This method should get inlined into the
16441685 // caller such that we can combine the partial apply with the apply in this
16451686 // function saving on allocating a closure context. This becomes unnecessary
16461687 // once we allocate noescape closures on the stack.
1647- public mutating func withUnsafeMutableBufferPointer< R> (
1648- _ body: ( inout UnsafeMutableBufferPointer < Element > ) throws -> R
1649- ) rethrows -> R {
1688+ public mutating func withUnsafeMutableBufferPointer< R, E > (
1689+ _ body: ( inout UnsafeMutableBufferPointer < Element > ) throws ( E ) -> R
1690+ ) throws ( E ) -> R {
16501691 _makeMutableAndUnique ( )
16511692 let count = _buffer. mutableCount
16521693
0 commit comments