@@ -712,13 +712,31 @@ extension MutableSpan where Element: ~Copyable {
712
712
/// - Complexity: O(1)
713
713
@_alwaysEmitIntoClient
714
714
@lifetime ( & self )
715
+ mutating public func _mutatingExtracting( _ bounds: Range < Index > ) -> Self {
716
+ _precondition (
717
+ UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
718
+ UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
719
+ " Index range out of bounds "
720
+ )
721
+ return unsafe _mutating Extracting( unchecked: bounds)
722
+ }
723
+
724
+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
725
+ @_alwaysEmitIntoClient
726
+ @lifetime ( & self )
715
727
mutating public func extracting( _ bounds: Range < Index > ) -> Self {
728
+ _mutatingExtracting ( bounds)
729
+ }
730
+
731
+ @_alwaysEmitIntoClient
732
+ @lifetime ( copy self)
733
+ consuming public func _consumingExtracting( _ bounds: Range < Index > ) -> Self {
716
734
_precondition (
717
735
UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
718
736
UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
719
737
" Index range out of bounds "
720
738
)
721
- return unsafe extracting ( unchecked: bounds)
739
+ return unsafe _ consumingExtracting ( unchecked: bounds)
722
740
}
723
741
724
742
/// Constructs a new span over the items within the supplied range of
@@ -739,13 +757,31 @@ extension MutableSpan where Element: ~Copyable {
739
757
@unsafe
740
758
@_alwaysEmitIntoClient
741
759
@lifetime ( & self )
742
- mutating public func extracting ( unchecked bounds: Range < Index > ) -> Self {
760
+ mutating public func _mutatingExtracting ( unchecked bounds: Range < Index > ) -> Self {
743
761
let delta = bounds. lowerBound &* MemoryLayout< Element> . stride
744
762
let newStart = unsafe _pointer? . advanced ( by: delta)
745
763
let newSpan = unsafe Self( _unchecked: newStart, count: bounds. count)
746
764
return unsafe _override Lifetime ( newSpan, mutating: & self )
747
765
}
748
766
767
+ @unsafe
768
+ @available ( * , deprecated, renamed: " _mutatingExtracting(unchecked:) " )
769
+ @_alwaysEmitIntoClient
770
+ @lifetime ( & self )
771
+ mutating public func extracting( unchecked bounds: Range < Index > ) -> Self {
772
+ unsafe _mutating Extracting( unchecked: bounds)
773
+ }
774
+
775
+ @unsafe
776
+ @_alwaysEmitIntoClient
777
+ @lifetime ( copy self)
778
+ consuming public func _consumingExtracting( unchecked bounds: Range < Index > ) -> Self {
779
+ let delta = bounds. lowerBound &* MemoryLayout< Element> . stride
780
+ let newStart = unsafe _pointer? . advanced ( by: delta)
781
+ let newSpan = unsafe Self( _unchecked: newStart, count: bounds. count)
782
+ return unsafe _override Lifetime ( newSpan, copying: self )
783
+ }
784
+
749
785
/// Constructs a new span over the items within the supplied range of
750
786
/// positions within this span.
751
787
///
@@ -761,10 +797,27 @@ extension MutableSpan where Element: ~Copyable {
761
797
/// - Complexity: O(1)
762
798
@_alwaysEmitIntoClient
763
799
@lifetime ( & self )
800
+ mutating public func _mutatingExtracting(
801
+ _ bounds: some RangeExpression < Index >
802
+ ) -> Self {
803
+ _mutatingExtracting ( bounds. relative ( to: indices) )
804
+ }
805
+
806
+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
807
+ @_alwaysEmitIntoClient
808
+ @lifetime ( & self )
764
809
mutating public func extracting(
765
810
_ bounds: some RangeExpression < Index >
766
811
) -> Self {
767
- extracting ( bounds. relative ( to: indices) )
812
+ _mutatingExtracting ( bounds)
813
+ }
814
+
815
+ @_alwaysEmitIntoClient
816
+ @lifetime ( copy self)
817
+ consuming public func _consumingExtracting(
818
+ _ bounds: some RangeExpression < Index >
819
+ ) -> Self {
820
+ _consumingExtracting ( bounds. relative ( to: indices) )
768
821
}
769
822
770
823
/// Constructs a new span over the items within the supplied range of
@@ -785,13 +838,35 @@ extension MutableSpan where Element: ~Copyable {
785
838
@unsafe
786
839
@_alwaysEmitIntoClient
787
840
@lifetime ( & self )
841
+ mutating public func _mutatingExtracting(
842
+ unchecked bounds: ClosedRange < Index >
843
+ ) -> Self {
844
+ let range = unsafe Range(
845
+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
846
+ )
847
+ return unsafe _mutating Extracting( unchecked: range)
848
+ }
849
+
850
+ @unsafe
851
+ @available ( * , deprecated, renamed: " _mutatingExtracting(unchecked:) " )
852
+ @_alwaysEmitIntoClient
853
+ @lifetime ( & self )
788
854
mutating public func extracting(
789
855
unchecked bounds: ClosedRange < Index >
856
+ ) -> Self {
857
+ unsafe _mutating Extracting( unchecked: bounds)
858
+ }
859
+
860
+ @unsafe
861
+ @_alwaysEmitIntoClient
862
+ @lifetime ( copy self)
863
+ consuming public func _consumingExtracting(
864
+ unchecked bounds: ClosedRange < Index >
790
865
) -> Self {
791
866
let range = unsafe Range(
792
- _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound&+ 1 )
867
+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
793
868
)
794
- return unsafe extracting ( unchecked: range)
869
+ return unsafe _ consumingExtracting ( unchecked: range)
795
870
}
796
871
797
872
/// Constructs a new span over all the items of this span.
@@ -805,10 +880,23 @@ extension MutableSpan where Element: ~Copyable {
805
880
/// - Complexity: O(1)
806
881
@_alwaysEmitIntoClient
807
882
@lifetime ( & self )
808
- mutating public func extracting ( _: UnboundedRange ) -> Self {
883
+ mutating public func _mutatingExtracting ( _: UnboundedRange ) -> Self {
809
884
let newSpan = unsafe Self( _unchecked: _pointer, count: _count)
810
885
return unsafe _override Lifetime ( newSpan, mutating: & self )
811
886
}
887
+
888
+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
889
+ @_alwaysEmitIntoClient
890
+ @lifetime ( & self )
891
+ mutating public func extracting( _: UnboundedRange ) -> Self {
892
+ _mutatingExtracting ( ... )
893
+ }
894
+
895
+ @_alwaysEmitIntoClient
896
+ @lifetime ( copy self)
897
+ consuming public func _consumingExtracting( _: UnboundedRange ) -> Self {
898
+ self
899
+ }
812
900
}
813
901
814
902
// MARK: prefixes and suffixes
@@ -833,7 +921,7 @@ extension MutableSpan where Element: ~Copyable {
833
921
/// - Complexity: O(1)
834
922
@_alwaysEmitIntoClient
835
923
@lifetime ( & self )
836
- mutating public func extracting ( first maxLength: Int ) -> Self {
924
+ mutating public func _mutatingExtracting ( first maxLength: Int ) -> Self {
837
925
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
838
926
_precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
839
927
let newCount = min ( maxLength, count)
@@ -844,6 +932,26 @@ extension MutableSpan where Element: ~Copyable {
844
932
#endif
845
933
}
846
934
935
+ @available ( * , deprecated, renamed: " _mutatingExtracting(first:) " )
936
+ @_alwaysEmitIntoClient
937
+ @lifetime ( & self )
938
+ mutating public func extracting( first maxLength: Int ) -> Self {
939
+ _mutatingExtracting ( first: maxLength)
940
+ }
941
+
942
+ @_alwaysEmitIntoClient
943
+ @lifetime ( copy self)
944
+ consuming public func _consumingExtracting( first maxLength: Int ) -> Self {
945
+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
946
+ _precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
947
+ let newCount = min ( maxLength, count)
948
+ let newSpan = unsafe Self( _unchecked: _pointer, count: newCount)
949
+ return unsafe _override Lifetime ( newSpan, copying: self )
950
+ #else
951
+ fatalError ( " Unsupported compiler " )
952
+ #endif
953
+ }
954
+
847
955
/// Returns a span over all but the given number of trailing elements.
848
956
///
849
957
/// If the number of elements to drop exceeds the number of elements in
@@ -860,7 +968,7 @@ extension MutableSpan where Element: ~Copyable {
860
968
/// - Complexity: O(1)
861
969
@_alwaysEmitIntoClient
862
970
@lifetime ( & self )
863
- mutating public func extracting ( droppingLast k: Int ) -> Self {
971
+ mutating public func _mutatingExtracting ( droppingLast k: Int ) -> Self {
864
972
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
865
973
_precondition ( k >= 0 , " Can't drop a negative number of elements " )
866
974
let droppedCount = min ( k, count)
@@ -872,6 +980,27 @@ extension MutableSpan where Element: ~Copyable {
872
980
#endif
873
981
}
874
982
983
+ @available ( * , deprecated, renamed: " _mutatingExtracting(droppingLast:) " )
984
+ @_alwaysEmitIntoClient
985
+ @lifetime ( & self )
986
+ mutating public func extracting( droppingLast k: Int ) -> Self {
987
+ _mutatingExtracting ( droppingLast: k)
988
+ }
989
+
990
+ @_alwaysEmitIntoClient
991
+ @lifetime ( copy self)
992
+ consuming public func _consumingExtracting( droppingLast k: Int ) -> Self {
993
+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
994
+ _precondition ( k >= 0 , " Can't drop a negative number of elements " )
995
+ let droppedCount = min ( k, count)
996
+ let newCount = count &- droppedCount
997
+ let newSpan = unsafe Self( _unchecked: _pointer, count: newCount)
998
+ return unsafe _override Lifetime ( newSpan, copying: self )
999
+ #else
1000
+ fatalError ( " Unsupported compiler " )
1001
+ #endif
1002
+ }
1003
+
875
1004
/// Returns a span containing the final elements of the span,
876
1005
/// up to the given maximum length.
877
1006
///
@@ -889,7 +1018,7 @@ extension MutableSpan where Element: ~Copyable {
889
1018
/// - Complexity: O(1)
890
1019
@_alwaysEmitIntoClient
891
1020
@lifetime ( & self )
892
- mutating public func extracting ( last maxLength: Int ) -> Self {
1021
+ mutating public func _mutatingExtracting ( last maxLength: Int ) -> Self {
893
1022
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
894
1023
_precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
895
1024
let newCount = min ( maxLength, count)
@@ -902,6 +1031,28 @@ extension MutableSpan where Element: ~Copyable {
902
1031
#endif
903
1032
}
904
1033
1034
+ @available ( * , deprecated, renamed: " _mutatingExtracting(last:) " )
1035
+ @_alwaysEmitIntoClient
1036
+ @lifetime ( & self )
1037
+ mutating public func extracting( last maxLength: Int ) -> Self {
1038
+ _mutatingExtracting ( last: maxLength)
1039
+ }
1040
+
1041
+ @_alwaysEmitIntoClient
1042
+ @lifetime ( copy self)
1043
+ consuming public func _consumingExtracting( last maxLength: Int ) -> Self {
1044
+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
1045
+ _precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
1046
+ let newCount = min ( maxLength, count)
1047
+ let offset = ( count &- newCount) * MemoryLayout< Element> . stride
1048
+ let newStart = unsafe _pointer? . advanced ( by: offset)
1049
+ let newSpan = unsafe Self( _unchecked: newStart, count: newCount)
1050
+ return unsafe _override Lifetime ( newSpan, copying: self )
1051
+ #else
1052
+ fatalError ( " Unsupported compiler " )
1053
+ #endif
1054
+ }
1055
+
905
1056
/// Returns a span over all but the given number of initial elements.
906
1057
///
907
1058
/// If the number of elements to drop exceeds the number of elements in
@@ -918,7 +1069,7 @@ extension MutableSpan where Element: ~Copyable {
918
1069
/// - Complexity: O(1)
919
1070
@_alwaysEmitIntoClient
920
1071
@lifetime ( & self )
921
- mutating public func extracting ( droppingFirst k: Int ) -> Self {
1072
+ mutating public func _mutatingExtracting ( droppingFirst k: Int ) -> Self {
922
1073
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
923
1074
_precondition ( k >= 0 , " Can't drop a negative number of elements " )
924
1075
let droppedCount = min ( k, count)
@@ -929,6 +1080,29 @@ extension MutableSpan where Element: ~Copyable {
929
1080
return unsafe _override Lifetime ( newSpan, mutating: & self )
930
1081
#else
931
1082
fatalError ( " Unsupported compiler " )
1083
+ #endif
1084
+ }
1085
+
1086
+ @available ( * , deprecated, renamed: " _mutatingExtracting(droppingFirst:) " )
1087
+ @_alwaysEmitIntoClient
1088
+ @lifetime ( & self )
1089
+ mutating public func extracting( droppingFirst k: Int ) -> Self {
1090
+ _mutatingExtracting ( droppingFirst: k)
1091
+ }
1092
+
1093
+ @_alwaysEmitIntoClient
1094
+ @lifetime ( copy self)
1095
+ consuming public func _consumingExtracting( droppingFirst k: Int ) -> Self {
1096
+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
1097
+ _precondition ( k >= 0 , " Can't drop a negative number of elements " )
1098
+ let droppedCount = min ( k, count)
1099
+ let offset = droppedCount * MemoryLayout< Element> . stride
1100
+ let newStart = unsafe _pointer? . advanced ( by: offset)
1101
+ let newCount = count &- droppedCount
1102
+ let newSpan = unsafe Self( _unchecked: newStart, count: newCount)
1103
+ return unsafe _override Lifetime ( newSpan, copying: self )
1104
+ #else
1105
+ fatalError ( " Unsupported compiler " )
932
1106
#endif
933
1107
}
934
1108
}
0 commit comments