Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion stdlib/public/core/UnsafeBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
@export(implementation)
@safe
public func extracting(_ bounds: Range<Int>) -> Self {
_precondition(_checkBounds(bounds), "Index out of range")
_debugPrecondition(_checkBounds(bounds), "Index out of range")
guard let start = self.baseAddress else {
return unsafe Self(start: nil, count: 0)
}
Expand Down Expand Up @@ -592,6 +592,7 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
/// - Returns: A new buffer pointer over the items at `bounds`.
@export(implementation)
public func extracting(unchecked bounds: Range<Int>) -> Self {
_internalInvariant(_checkBounds(bounds), "Index out of range")
let newStart = unsafe _position?.advanced(by: bounds.lowerBound)
return unsafe Self(start: newStart, count: bounds.count)
}
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/UnsafeRawBufferPointer.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1222,7 +1222,7 @@ extension Unsafe${Mutable}RawBufferPointer {
@export(implementation)
@safe
public func extracting(_ bounds: Range<Int>) -> Self {
_precondition(_checkBounds(bounds), "Byte offset out of range")
_debugPrecondition(_checkBounds(bounds), "Byte offset out of range")
guard let start = baseAddress else {
return unsafe Self(_uncheckedStart: nil, count: 0)
}
Expand Down Expand Up @@ -1267,6 +1267,7 @@ extension Unsafe${Mutable}RawBufferPointer {
/// - Returns: A new buffer pointer over the bytes at `bounds`.
@export(implementation)
public func extracting(unchecked bounds: Range<Int>) -> Self {
_internalInvariant(_checkBounds(bounds), "Byte offset out of range")
let newStart = unsafe baseAddress?.advanced(by: bounds.lowerBound)
return unsafe Self(_uncheckedStart: newStart, count: bounds.count)
}
Expand Down