@@ -1428,25 +1428,6 @@ extension Array: RangeReplaceableCollection {
1428
1428
}
1429
1429
}
1430
1430
1431
- @available ( SwiftStdlib 6 . 2 , * )
1432
- public var span : Span < Element > {
1433
- @lifetime ( borrow self)
1434
- @_alwaysEmitIntoClient
1435
- borrowing get {
1436
- #if _runtime(_ObjC)
1437
- if _slowPath ( !_buffer. _isNative) {
1438
- let buffer = _buffer. getOrAllocateAssociatedObjectBuffer ( )
1439
- let ( pointer, count) = unsafe ( buffer. firstElementAddress, buffer. count)
1440
- let span = unsafe Span( _unsafeStart: pointer, count: count)
1441
- return unsafe _override Lifetime ( span, borrowing: self )
1442
- }
1443
- #endif
1444
- let ( pointer, count) = unsafe ( _buffer. firstElementAddress, _buffer. count)
1445
- let span = unsafe Span( _unsafeStart: pointer, count: count)
1446
- return unsafe _override Lifetime ( span, borrowing: self )
1447
- }
1448
- }
1449
-
1450
1431
@inlinable
1451
1432
public __consuming func _copyToContiguousArray( ) -> ContiguousArray < Element > {
1452
1433
if let n = _buffer. requestNativeBuffer ( ) {
@@ -1630,6 +1611,27 @@ extension Array {
1630
1611
return try unsafe _buffer. withUnsafeBufferPointer ( body)
1631
1612
}
1632
1613
1614
+ @available ( SwiftStdlib 6 . 2 , * )
1615
+ public var span : Span < Element > {
1616
+ @lifetime ( borrow self)
1617
+ @_alwaysEmitIntoClient
1618
+ borrowing get {
1619
+ #if _runtime(_ObjC)
1620
+ if _slowPath ( !_buffer. _isNative) {
1621
+ let buffer = _buffer. getOrAllocateAssociatedObjectBuffer ( )
1622
+ let pointer = unsafe buffer. firstElementAddress
1623
+ let count = buffer. immutableCount
1624
+ let span = unsafe Span( _unsafeStart: pointer, count: count)
1625
+ return unsafe _override Lifetime ( span, borrowing: self )
1626
+ }
1627
+ #endif
1628
+ let pointer = unsafe _buffer . firstElementAddress
1629
+ let count = _buffer. immutableCount
1630
+ let span = unsafe Span( _unsafeStart: pointer, count: count)
1631
+ return unsafe _override Lifetime ( span, borrowing: self )
1632
+ }
1633
+ }
1634
+
1633
1635
// Superseded by the typed-throws version of this function, but retained
1634
1636
// for ABI reasons.
1635
1637
@_semantics ( " array.withUnsafeMutableBufferPointer " )
@@ -1728,6 +1730,22 @@ extension Array {
1728
1730
return try unsafe body( & inoutBufferPointer)
1729
1731
}
1730
1732
1733
+ @available ( SwiftStdlib 6 . 2 , * )
1734
+ public var mutableSpan : MutableSpan < Element > {
1735
+ @lifetime ( /*inout*/borrow self)
1736
+ @_alwaysEmitIntoClient
1737
+ mutating get {
1738
+ _makeMutableAndUnique ( )
1739
+ // NOTE: We don't have the ability to schedule a call to
1740
+ // ContiguousArrayBuffer.endCOWMutation().
1741
+ // rdar://146785284 (lifetime analysis for end of mutation)
1742
+ let pointer = unsafe _buffer . firstElementAddress
1743
+ let count = _buffer. mutableCount
1744
+ let span = unsafe MutableSpan( _unsafeStart: pointer, count: count)
1745
+ return unsafe _override Lifetime ( span, mutating: & self )
1746
+ }
1747
+ }
1748
+
1731
1749
@inlinable
1732
1750
public __consuming func _copyContents(
1733
1751
initializing buffer: UnsafeMutableBufferPointer < Element >
0 commit comments