Skip to content

Commit cf16c1b

Browse files
committed
stdlib: revert workaround for Span bounds checking
1 parent a34913d commit cf16c1b

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

stdlib/public/core/Span/MutableSpan.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,18 +290,12 @@ extension MutableSpan where Element: ~Copyable {
290290
@_alwaysEmitIntoClient
291291
public subscript(_ position: Index) -> Element {
292292
unsafeAddress {
293-
_precondition(
294-
UInt(bitPattern: position) < UInt(bitPattern: _count),
295-
"Index out of bounds"
296-
)
293+
_precondition(indices.contains(position), "index out of bounds")
297294
return unsafe UnsafePointer(_unsafeAddressOfElement(unchecked: position))
298295
}
299296
@lifetime(self: copy self)
300297
unsafeMutableAddress {
301-
_precondition(
302-
UInt(bitPattern: position) < UInt(bitPattern: _count),
303-
"Index out of bounds"
304-
)
298+
_precondition(indices.contains(position), "index out of bounds")
305299
return unsafe _unsafeAddressOfElement(unchecked: position)
306300
}
307301
}

stdlib/public/core/Span/Span.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,7 @@ extension Span where Element: ~Copyable {
419419
@inline(__always)
420420
@_alwaysEmitIntoClient
421421
internal func _checkIndex(_ position: Index) {
422-
_precondition(
423-
UInt(bitPattern: position) < UInt(bitPattern: _count),
424-
"Index out of bounds"
425-
)
422+
_precondition(indices.contains(position), "Index out of bounds")
426423
}
427424

428425
/// Accesses the element at the specified position in the `Span`.

0 commit comments

Comments
 (0)