Skip to content

Commit ac3e476

Browse files
committed
[stdlib] rename Span.extracting functions
1 parent 3c98a1e commit ac3e476

File tree

5 files changed

+120
-55
lines changed

5 files changed

+120
-55
lines changed

stdlib/public/core/Span/Span.swift

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,20 @@ extension Span where Element: ~Copyable {
536536
/// - Complexity: O(1)
537537
@_alwaysEmitIntoClient
538538
@lifetime(copy self)
539-
public func _extracting(_ bounds: Range<Index>) -> Self {
539+
public func extracting(_ bounds: Range<Index>) -> Self {
540540
_precondition(
541541
UInt(bitPattern: bounds.lowerBound) <= UInt(bitPattern: _count) &&
542542
UInt(bitPattern: bounds.upperBound) <= UInt(bitPattern: _count),
543543
"Index range out of bounds"
544544
)
545-
return unsafe _extracting(unchecked: bounds)
545+
return unsafe extracting(unchecked: bounds)
546+
}
547+
548+
@available(*, deprecated, renamed: "extracting(_:)")
549+
@_alwaysEmitIntoClient
550+
@lifetime(copy self)
551+
public func _extracting(_ bounds: Range<Index>) -> Self {
552+
extracting(bounds)
546553
}
547554

548555
/// Constructs a new span over the items within the supplied range of
@@ -563,7 +570,7 @@ extension Span where Element: ~Copyable {
563570
@unsafe
564571
@_alwaysEmitIntoClient
565572
@lifetime(copy self)
566-
public func _extracting(unchecked bounds: Range<Index>) -> Self {
573+
public func extracting(unchecked bounds: Range<Index>) -> Self {
567574
let delta = bounds.lowerBound &* MemoryLayout<Element>.stride
568575
let newStart = unsafe _pointer?.advanced(by: delta)
569576
let newSpan = unsafe Span(_unchecked: newStart, count: bounds.count)
@@ -572,6 +579,14 @@ extension Span where Element: ~Copyable {
572579
return unsafe _overrideLifetime(newSpan, copying: self)
573580
}
574581

582+
@unsafe
583+
@available(*, deprecated, renamed: "extracting(unchecked:)")
584+
@_alwaysEmitIntoClient
585+
@lifetime(copy self)
586+
public func _extracting(unchecked bounds: Range<Index>) -> Self {
587+
unsafe extracting(unchecked: bounds)
588+
}
589+
575590
/// Constructs a new span over the items within the supplied range of
576591
/// positions within this span.
577592
///
@@ -587,10 +602,17 @@ extension Span where Element: ~Copyable {
587602
/// - Complexity: O(1)
588603
@_alwaysEmitIntoClient
589604
@lifetime(copy self)
590-
public func _extracting(
605+
public func extracting(
591606
_ bounds: some RangeExpression<Index>
592607
) -> Self {
593-
_extracting(bounds.relative(to: indices))
608+
extracting(bounds.relative(to: indices))
609+
}
610+
611+
@available(*, deprecated, renamed: "extracting(_:)")
612+
@_alwaysEmitIntoClient
613+
@lifetime(copy self)
614+
public func _extracting(_ bounds: some RangeExpression<Index>) -> Self {
615+
extracting(bounds)
594616
}
595617

596618
/// Constructs a new span over the items within the supplied range of
@@ -611,13 +633,21 @@ extension Span where Element: ~Copyable {
611633
@unsafe
612634
@_alwaysEmitIntoClient
613635
@lifetime(copy self)
614-
public func _extracting(
636+
public func extracting(
615637
unchecked bounds: ClosedRange<Index>
616638
) -> Self {
617639
let range = unsafe Range(
618640
_uncheckedBounds: (bounds.lowerBound, bounds.upperBound + 1)
619641
)
620-
return unsafe _extracting(unchecked: range)
642+
return unsafe extracting(unchecked: range)
643+
}
644+
645+
@unsafe
646+
@available(*, deprecated, renamed: "extracting(unchecked:)")
647+
@_alwaysEmitIntoClient
648+
@lifetime(copy self)
649+
public func _extracting(unchecked bounds: ClosedRange<Index>) -> Self {
650+
unsafe extracting(unchecked: bounds)
621651
}
622652

623653
/// Constructs a new span over all the items of this span.
@@ -631,6 +661,13 @@ extension Span where Element: ~Copyable {
631661
/// - Complexity: O(1)
632662
@_alwaysEmitIntoClient
633663
@lifetime(copy self)
664+
public func extracting(_: UnboundedRange) -> Self {
665+
self
666+
}
667+
668+
@available(*, deprecated, renamed: "extracting(_:)")
669+
@_alwaysEmitIntoClient
670+
@lifetime(copy self)
634671
public func _extracting(_: UnboundedRange) -> Self {
635672
self
636673
}
@@ -761,13 +798,20 @@ extension Span where Element: ~Copyable {
761798
/// - Complexity: O(1)
762799
@_alwaysEmitIntoClient
763800
@lifetime(copy self)
764-
public func _extracting(first maxLength: Int) -> Self {
801+
public func extracting(first maxLength: Int) -> Self {
765802
_precondition(maxLength >= 0, "Can't have a prefix of negative length")
766803
let newCount = min(maxLength, count)
767804
let newSpan = unsafe Self(_unchecked: _pointer, count: newCount)
768805
return unsafe _overrideLifetime(newSpan, copying: self)
769806
}
770807

808+
@available(*, deprecated, renamed: "extracting(first:)")
809+
@_alwaysEmitIntoClient
810+
@lifetime(copy self)
811+
public func _extracting(first maxLength: Int) -> Self {
812+
extracting(first: maxLength)
813+
}
814+
771815
/// Returns a span over all but the given number of trailing elements.
772816
///
773817
/// If the number of elements to drop exceeds the number of elements in
@@ -784,13 +828,20 @@ extension Span where Element: ~Copyable {
784828
/// - Complexity: O(1)
785829
@_alwaysEmitIntoClient
786830
@lifetime(copy self)
787-
public func _extracting(droppingLast k: Int) -> Self {
831+
public func extracting(droppingLast k: Int) -> Self {
788832
_precondition(k >= 0, "Can't drop a negative number of elements")
789833
let droppedCount = min(k, count)
790834
let newSpan = unsafe Self(_unchecked: _pointer, count: count &- droppedCount)
791835
return unsafe _overrideLifetime(newSpan, copying: self)
792836
}
793837

838+
@available(*, deprecated, renamed: "extracting(droppingLast:)")
839+
@_alwaysEmitIntoClient
840+
@lifetime(copy self)
841+
public func _extracting(droppingLast k: Int) -> Self {
842+
extracting(droppingLast: k)
843+
}
844+
794845
/// Returns a span containing the final elements of the span,
795846
/// up to the given maximum length.
796847
///
@@ -808,7 +859,7 @@ extension Span where Element: ~Copyable {
808859
/// - Complexity: O(1)
809860
@_alwaysEmitIntoClient
810861
@lifetime(copy self)
811-
public func _extracting(last maxLength: Int) -> Self {
862+
public func extracting(last maxLength: Int) -> Self {
812863
_precondition(maxLength >= 0, "Can't have a suffix of negative length")
813864
let newCount = min(maxLength, count)
814865
let offset = (count &- newCount) * MemoryLayout<Element>.stride
@@ -819,6 +870,13 @@ extension Span where Element: ~Copyable {
819870
return unsafe _overrideLifetime(newSpan, copying: self)
820871
}
821872

873+
@available(*, deprecated, renamed: "extracting(last:)")
874+
@_alwaysEmitIntoClient
875+
@lifetime(copy self)
876+
public func _extracting(last maxLength: Int) -> Self {
877+
extracting(last: maxLength)
878+
}
879+
822880
/// Returns a span over all but the given number of initial elements.
823881
///
824882
/// If the number of elements to drop exceeds the number of elements in
@@ -835,7 +893,7 @@ extension Span where Element: ~Copyable {
835893
/// - Complexity: O(1)
836894
@_alwaysEmitIntoClient
837895
@lifetime(copy self)
838-
public func _extracting(droppingFirst k: Int) -> Self {
896+
public func extracting(droppingFirst k: Int) -> Self {
839897
_precondition(k >= 0, "Can't drop a negative number of elements")
840898
let droppedCount = min(k, count)
841899
let offset = droppedCount &* MemoryLayout<Element>.stride
@@ -846,4 +904,11 @@ extension Span where Element: ~Copyable {
846904
// lifetime of 'buffer'. Make the dependence explicit.
847905
return unsafe _overrideLifetime(newSpan, copying: self)
848906
}
907+
908+
@available(*, deprecated, renamed: "extracting(droppingFirst:)")
909+
@_alwaysEmitIntoClient
910+
@lifetime(copy self)
911+
public func _extracting(droppingFirst k: Int) -> Self {
912+
extracting(droppingFirst: k)
913+
}
849914
}

stdlib/public/core/Substring.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ extension Substring.UTF8View {
760760
let base: String.UTF8View = self._base
761761
let first = base._foreignDistance(from: base.startIndex, to: startIndex)
762762
let count = base._foreignDistance(from: startIndex, to: endIndex)
763-
let span = base._underlyingSpan()._extracting(first..<(first &+ count))
763+
let span = base._underlyingSpan().extracting(first..<(first &+ count))
764764
return unsafe _overrideLifetime(span, borrowing: self)
765765
}
766766
#endif // _runtime(_ObjC)
@@ -776,7 +776,7 @@ extension Substring.UTF8View {
776776
let isFastUTF8 = _wholeGuts.isFastUTF8
777777
_precondition(isFastUTF8, "Substring must be contiguous UTF8")
778778
var span = unsafe Span(_unsafeElements: _wholeGuts._object.fastUTF8)
779-
span = span._extracting(first..<end)
779+
span = span.extracting(first..<end)
780780
return unsafe _overrideLifetime(span, borrowing: self)
781781
}
782782

stdlib/public/core/UTF8Span.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ extension Substring {
313313
let base: String.UTF8View = _slice._base.utf8
314314
let first = base._foreignDistance(from: base.startIndex, to: startIndex)
315315
let count = base._foreignDistance(from: startIndex, to: endIndex)
316-
let span = base._underlyingSpan()._extracting(first..<(first &+ count))
316+
let span = base._underlyingSpan().extracting(first..<(first &+ count))
317317
return unsafe _overrideLifetime(span, borrowing: self)
318318
}
319319
#endif // _runtime(_ObjC)
@@ -329,7 +329,7 @@ extension Substring {
329329
let isFastUTF8 = _wholeGuts.isFastUTF8
330330
_precondition(isFastUTF8, "Substring must be contiguous UTF8")
331331
var span = unsafe Span(_unsafeElements: _wholeGuts._object.fastUTF8)
332-
span = span._extracting(first..<end)
332+
span = span.extracting(first..<end)
333333
return unsafe _overrideLifetime(span, borrowing: self)
334334
}
335335

stdlib/public/core/UTF8SpanIterators.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ extension UTF8Span {
174174
/// The resultant `UTF8Span` has the same lifetime constraints as `self`.
175175
@lifetime(copy self)
176176
public func prefix() -> UTF8Span {
177-
let slice = codeUnits.span._extracting(0..<currentCodeUnitOffset)
177+
let slice = codeUnits.span.extracting(0..<currentCodeUnitOffset)
178178
return UTF8Span(
179179
_uncheckedAssumingValidUTF8: slice,
180180
isKnownASCII: codeUnits.isKnownASCII,
@@ -187,7 +187,7 @@ extension UTF8Span {
187187
/// The resultant `UTF8Span` has the same lifetime constraints as `self`.
188188
@lifetime(copy self)
189189
public func suffix() -> UTF8Span {
190-
let slice = codeUnits.span._extracting(currentCodeUnitOffset..<codeUnits.count)
190+
let slice = codeUnits.span.extracting(currentCodeUnitOffset..<codeUnits.count)
191191
return UTF8Span(
192192
_uncheckedAssumingValidUTF8: slice,
193193
isKnownASCII: codeUnits.isKnownASCII,
@@ -368,7 +368,7 @@ extension UTF8Span {
368368
/// current position.
369369
@lifetime(copy self)
370370
public func prefix() -> UTF8Span {
371-
let slice = codeUnits.span._extracting(0..<currentCodeUnitOffset)
371+
let slice = codeUnits.span.extracting(0..<currentCodeUnitOffset)
372372
return UTF8Span(
373373
_uncheckedAssumingValidUTF8: slice,
374374
isKnownASCII: codeUnits.isKnownASCII,
@@ -379,7 +379,7 @@ extension UTF8Span {
379379
/// current position.
380380
@lifetime(copy self)
381381
public func suffix() -> UTF8Span {
382-
let slice = codeUnits.span._extracting(currentCodeUnitOffset..<codeUnits.count)
382+
let slice = codeUnits.span.extracting(currentCodeUnitOffset..<codeUnits.count)
383383
return UTF8Span(
384384
_uncheckedAssumingValidUTF8: slice,
385385
isKnownASCII: codeUnits.isKnownASCII,

0 commit comments

Comments
 (0)