Skip to content

Commit ecebaa5

Browse files
committed
[stdlib] move span properties of array types
…to a more logical spot in each of their files
1 parent 90684a8 commit ecebaa5

File tree

3 files changed

+44
-41
lines changed

3 files changed

+44
-41
lines changed

stdlib/public/core/Array.swift

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,25 +1428,6 @@ extension Array: RangeReplaceableCollection {
14281428
}
14291429
}
14301430

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 _overrideLifetime(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 _overrideLifetime(span, borrowing: self)
1447-
}
1448-
}
1449-
14501431
@inlinable
14511432
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
14521433
if let n = _buffer.requestNativeBuffer() {
@@ -1630,6 +1611,27 @@ extension Array {
16301611
return try unsafe _buffer.withUnsafeBufferPointer(body)
16311612
}
16321613

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 _overrideLifetime(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 _overrideLifetime(span, borrowing: self)
1632+
}
1633+
}
1634+
16331635
// Superseded by the typed-throws version of this function, but retained
16341636
// for ABI reasons.
16351637
@_semantics("array.withUnsafeMutableBufferPointer")

stdlib/public/core/ArraySlice.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,17 +1116,6 @@ extension ArraySlice: RangeReplaceableCollection {
11161116
}
11171117
}
11181118

1119-
@available(SwiftStdlib 6.2, *)
1120-
public var span: Span<Element> {
1121-
@lifetime(borrow self)
1122-
@_alwaysEmitIntoClient
1123-
borrowing get {
1124-
let (pointer, count) = (_buffer.firstElementAddress, _buffer.count)
1125-
let span = unsafe Span(_unsafeStart: pointer, count: count)
1126-
return unsafe _overrideLifetime(span, borrowing: self)
1127-
}
1128-
}
1129-
11301119
@inlinable
11311120
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
11321121
if let n = _buffer.requestNativeBuffer() {
@@ -1221,6 +1210,17 @@ extension ArraySlice {
12211210
return try _buffer.withUnsafeBufferPointer(body)
12221211
}
12231212

1213+
@available(SwiftStdlib 6.2, *)
1214+
public var span: Span<Element> {
1215+
@lifetime(borrow self)
1216+
@_alwaysEmitIntoClient
1217+
borrowing get {
1218+
let (pointer, count) = unsafe (_buffer.firstElementAddress, _buffer.count)
1219+
let span = unsafe Span(_unsafeStart: pointer, count: count)
1220+
return unsafe _overrideLifetime(span, borrowing: self)
1221+
}
1222+
}
1223+
12241224
// Superseded by the typed-throws version of this function, but retained
12251225
// for ABI reasons.
12261226
@_semantics("array.withUnsafeMutableBufferPointer")

stdlib/public/core/ContiguousArray.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,17 +1021,6 @@ extension ContiguousArray: RangeReplaceableCollection {
10211021
}
10221022
}
10231023

1024-
@available(SwiftStdlib 6.2, *)
1025-
public var span: Span<Element> {
1026-
@lifetime(borrow self)
1027-
@_alwaysEmitIntoClient
1028-
borrowing get {
1029-
let (pointer, count) = unsafe (_buffer.firstElementAddress, _buffer.count)
1030-
let span = unsafe Span(_unsafeStart: pointer, count: count)
1031-
return unsafe _overrideLifetime(span, borrowing: self)
1032-
}
1033-
}
1034-
10351024
@inlinable
10361025
public __consuming func _copyToContiguousArray() -> ContiguousArray<Element> {
10371026
if let n = _buffer.requestNativeBuffer() {
@@ -1163,6 +1152,18 @@ extension ContiguousArray {
11631152
return try unsafe _buffer.withUnsafeBufferPointer(body)
11641153
}
11651154

1155+
@available(SwiftStdlib 6.2, *)
1156+
public var span: Span<Element> {
1157+
@lifetime(borrow self)
1158+
@_alwaysEmitIntoClient
1159+
borrowing get {
1160+
let pointer = unsafe _buffer.firstElementAddress
1161+
let count = _buffer.immutableCount
1162+
let span = unsafe Span(_unsafeStart: pointer, count: count)
1163+
return unsafe _overrideLifetime(span, borrowing: self)
1164+
}
1165+
}
1166+
11661167
// Superseded by the typed-throws version of this function, but retained
11671168
// for ABI reasons.
11681169
@_semantics("array.withUnsafeMutableBufferPointer")

0 commit comments

Comments
 (0)