@@ -712,13 +712,31 @@ extension MutableSpan where Element: ~Copyable {
712712 /// - Complexity: O(1)
713713 @_alwaysEmitIntoClient
714714 @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 )
715727 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 {
716734 _precondition (
717735 UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
718736 UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
719737 " Index range out of bounds "
720738 )
721- return unsafe extracting ( unchecked: bounds)
739+ return unsafe _ consumingExtracting ( unchecked: bounds)
722740 }
723741
724742 /// Constructs a new span over the items within the supplied range of
@@ -739,13 +757,31 @@ extension MutableSpan where Element: ~Copyable {
739757 @unsafe
740758 @_alwaysEmitIntoClient
741759 @lifetime ( & self )
742- mutating public func extracting ( unchecked bounds: Range < Index > ) -> Self {
760+ mutating public func _mutatingExtracting ( unchecked bounds: Range < Index > ) -> Self {
743761 let delta = bounds. lowerBound &* MemoryLayout< Element> . stride
744762 let newStart = unsafe _pointer? . advanced ( by: delta)
745763 let newSpan = unsafe Self( _unchecked: newStart, count: bounds. count)
746764 return unsafe _override Lifetime ( newSpan, mutating: & self )
747765 }
748766
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+
749785 /// Constructs a new span over the items within the supplied range of
750786 /// positions within this span.
751787 ///
@@ -761,10 +797,27 @@ extension MutableSpan where Element: ~Copyable {
761797 /// - Complexity: O(1)
762798 @_alwaysEmitIntoClient
763799 @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 )
764809 mutating public func extracting(
765810 _ bounds: some RangeExpression < Index >
766811 ) -> 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) )
768821 }
769822
770823 /// Constructs a new span over the items within the supplied range of
@@ -785,13 +838,35 @@ extension MutableSpan where Element: ~Copyable {
785838 @unsafe
786839 @_alwaysEmitIntoClient
787840 @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 )
788854 mutating public func extracting(
789855 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 >
790865 ) -> Self {
791866 let range = unsafe Range(
792- _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound&+ 1 )
867+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
793868 )
794- return unsafe extracting ( unchecked: range)
869+ return unsafe _ consumingExtracting ( unchecked: range)
795870 }
796871
797872 /// Constructs a new span over all the items of this span.
@@ -805,10 +880,23 @@ extension MutableSpan where Element: ~Copyable {
805880 /// - Complexity: O(1)
806881 @_alwaysEmitIntoClient
807882 @lifetime ( & self )
808- mutating public func extracting ( _: UnboundedRange ) -> Self {
883+ mutating public func _mutatingExtracting ( _: UnboundedRange ) -> Self {
809884 let newSpan = unsafe Self( _unchecked: _pointer, count: _count)
810885 return unsafe _override Lifetime ( newSpan, mutating: & self )
811886 }
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+ }
812900}
813901
814902// MARK: prefixes and suffixes
@@ -833,7 +921,7 @@ extension MutableSpan where Element: ~Copyable {
833921 /// - Complexity: O(1)
834922 @_alwaysEmitIntoClient
835923 @lifetime ( & self )
836- mutating public func extracting ( first maxLength: Int ) -> Self {
924+ mutating public func _mutatingExtracting ( first maxLength: Int ) -> Self {
837925#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
838926 _precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
839927 let newCount = min ( maxLength, count)
@@ -844,6 +932,26 @@ extension MutableSpan where Element: ~Copyable {
844932#endif
845933 }
846934
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+
847955 /// Returns a span over all but the given number of trailing elements.
848956 ///
849957 /// If the number of elements to drop exceeds the number of elements in
@@ -860,7 +968,7 @@ extension MutableSpan where Element: ~Copyable {
860968 /// - Complexity: O(1)
861969 @_alwaysEmitIntoClient
862970 @lifetime ( & self )
863- mutating public func extracting ( droppingLast k: Int ) -> Self {
971+ mutating public func _mutatingExtracting ( droppingLast k: Int ) -> Self {
864972#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
865973 _precondition ( k >= 0 , " Can't drop a negative number of elements " )
866974 let droppedCount = min ( k, count)
@@ -872,6 +980,27 @@ extension MutableSpan where Element: ~Copyable {
872980#endif
873981 }
874982
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+
8751004 /// Returns a span containing the final elements of the span,
8761005 /// up to the given maximum length.
8771006 ///
@@ -889,7 +1018,7 @@ extension MutableSpan where Element: ~Copyable {
8891018 /// - Complexity: O(1)
8901019 @_alwaysEmitIntoClient
8911020 @lifetime ( & self )
892- mutating public func extracting ( last maxLength: Int ) -> Self {
1021+ mutating public func _mutatingExtracting ( last maxLength: Int ) -> Self {
8931022#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
8941023 _precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
8951024 let newCount = min ( maxLength, count)
@@ -902,6 +1031,28 @@ extension MutableSpan where Element: ~Copyable {
9021031#endif
9031032 }
9041033
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+
9051056 /// Returns a span over all but the given number of initial elements.
9061057 ///
9071058 /// If the number of elements to drop exceeds the number of elements in
@@ -918,7 +1069,7 @@ extension MutableSpan where Element: ~Copyable {
9181069 /// - Complexity: O(1)
9191070 @_alwaysEmitIntoClient
9201071 @lifetime ( & self )
921- mutating public func extracting ( droppingFirst k: Int ) -> Self {
1072+ mutating public func _mutatingExtracting ( droppingFirst k: Int ) -> Self {
9221073#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
9231074 _precondition ( k >= 0 , " Can't drop a negative number of elements " )
9241075 let droppedCount = min ( k, count)
@@ -929,6 +1080,29 @@ extension MutableSpan where Element: ~Copyable {
9291080 return unsafe _override Lifetime ( newSpan, mutating: & self )
9301081#else
9311082 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 " )
9321106#endif
9331107 }
9341108}
0 commit comments