Skip to content

Commit bd84291

Browse files
committed
[stdlib] add an _extracting() overload for ClosedRange
1 parent e3f3cd8 commit bd84291

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

stdlib/public/core/Span/RawSpan.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,17 @@ extension RawSpan {
421421
unsafe _extracting(unchecked: bounds.relative(to: byteOffsets))
422422
}
423423

424+
@_alwaysEmitIntoClient
425+
@lifetime(self)
426+
public func _extracting(
427+
unchecked bounds: ClosedRange<Int>
428+
) -> Self {
429+
let range = Range(
430+
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound&+1)
431+
)
432+
return unsafe _extracting(unchecked: range)
433+
}
434+
424435
/// Constructs a new span over all the bytes of this span.
425436
///
426437
/// The returned span's first byte is always at offset 0; unlike buffer

stdlib/public/core/Span/Span.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,17 @@ extension Span where Element: ~Copyable {
575575
unsafe _extracting(unchecked: bounds.relative(to: indices))
576576
}
577577

578+
@_alwaysEmitIntoClient
579+
@lifetime(self)
580+
public func _extracting(
581+
unchecked bounds: ClosedRange<Index>
582+
) -> Self {
583+
let range = Range(
584+
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound&+1)
585+
)
586+
return unsafe _extracting(unchecked: range)
587+
}
588+
578589
/// Constructs a new span over all the items of this span.
579590
///
580591
/// The returned span's first item is always at offset 0; unlike buffer

0 commit comments

Comments
 (0)