@@ -482,13 +482,31 @@ extension MutableRawSpan {
482482 /// - Complexity: O(1)
483483 @_alwaysEmitIntoClient
484484 @lifetime ( & self )
485+ mutating public func _mutatingExtracting( _ bounds: Range < Int > ) -> Self {
486+ _precondition (
487+ UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
488+ UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
489+ " Index range out of bounds "
490+ )
491+ return unsafe _mutating Extracting( unchecked: bounds)
492+ }
493+
494+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
495+ @_alwaysEmitIntoClient
496+ @lifetime ( & self )
485497 mutating public func extracting( _ bounds: Range < Int > ) -> Self {
498+ _mutatingExtracting ( bounds)
499+ }
500+
501+ @_alwaysEmitIntoClient
502+ @lifetime ( copy self)
503+ consuming public func _consumingExtracting( _ bounds: Range < Int > ) -> Self {
486504 _precondition (
487505 UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
488506 UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
489507 " Index range out of bounds "
490508 )
491- return unsafe extracting ( unchecked: bounds)
509+ return unsafe _ consumingExtracting ( unchecked: bounds)
492510 }
493511
494512 /// Constructs a new span over the items within the supplied range of
@@ -509,12 +527,29 @@ extension MutableRawSpan {
509527 @unsafe
510528 @_alwaysEmitIntoClient
511529 @lifetime ( & self )
512- mutating public func extracting ( unchecked bounds: Range < Int > ) -> Self {
530+ mutating public func _mutatingExtracting ( unchecked bounds: Range < Int > ) -> Self {
513531 let newStart = unsafe _pointer? . advanced ( by: bounds. lowerBound)
514532 let newSpan = unsafe Self( _unchecked: newStart, byteCount: bounds. count)
515533 return unsafe _override Lifetime ( newSpan, mutating: & self )
516534 }
517535
536+ @unsafe
537+ @available ( * , deprecated, renamed: " _mutatingExtracting(unchecked:) " )
538+ @_alwaysEmitIntoClient
539+ @lifetime ( & self )
540+ mutating public func extracting( unchecked bounds: Range < Int > ) -> Self {
541+ unsafe _mutating Extracting( unchecked: bounds)
542+ }
543+
544+ @unsafe
545+ @_alwaysEmitIntoClient
546+ @lifetime ( copy self)
547+ consuming public func _consumingExtracting( unchecked bounds: Range < Int > ) -> Self {
548+ let newStart = unsafe _pointer? . advanced ( by: bounds. lowerBound)
549+ let newSpan = unsafe Self( _unchecked: newStart, byteCount: bounds. count)
550+ return unsafe _override Lifetime ( newSpan, copying: self )
551+ }
552+
518553 /// Constructs a new span over the items within the supplied range of
519554 /// positions within this span.
520555 ///
@@ -530,10 +565,27 @@ extension MutableRawSpan {
530565 /// - Complexity: O(1)
531566 @_alwaysEmitIntoClient
532567 @lifetime ( & self )
568+ mutating public func _mutatingExtracting(
569+ _ bounds: some RangeExpression < Int >
570+ ) -> Self {
571+ _mutatingExtracting ( bounds. relative ( to: byteOffsets) )
572+ }
573+
574+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
575+ @_alwaysEmitIntoClient
576+ @lifetime ( & self )
533577 mutating public func extracting(
534578 _ bounds: some RangeExpression < Int >
535579 ) -> Self {
536- extracting ( bounds. relative ( to: byteOffsets) )
580+ _mutatingExtracting ( bounds)
581+ }
582+
583+ @_alwaysEmitIntoClient
584+ @lifetime ( copy self)
585+ consuming public func _consumingExtracting(
586+ _ bounds: some RangeExpression < Int >
587+ ) -> Self {
588+ _consumingExtracting ( bounds. relative ( to: byteOffsets) )
537589 }
538590
539591 /// Constructs a new span over the items within the supplied range of
@@ -554,11 +606,35 @@ extension MutableRawSpan {
554606 @unsafe
555607 @_alwaysEmitIntoClient
556608 @lifetime ( & self )
557- mutating public func extracting( unchecked bounds: ClosedRange < Int > ) -> Self {
609+ mutating public func _mutatingExtracting(
610+ unchecked bounds: ClosedRange < Int >
611+ ) -> Self {
612+ let range = unsafe Range(
613+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
614+ )
615+ return unsafe _mutating Extracting( unchecked: range)
616+ }
617+
618+ @unsafe
619+ @available ( * , deprecated, renamed: " _mutatingExtracting(unchecked:) " )
620+ @_alwaysEmitIntoClient
621+ @lifetime ( & self )
622+ mutating public func extracting(
623+ unchecked bounds: ClosedRange < Int >
624+ ) -> Self {
625+ unsafe _mutating Extracting( unchecked: bounds)
626+ }
627+
628+ @unsafe
629+ @_alwaysEmitIntoClient
630+ @lifetime ( copy self)
631+ consuming public func _consumingExtracting(
632+ unchecked bounds: ClosedRange < Int >
633+ ) -> Self {
558634 let range = unsafe Range(
559- _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound+ 1 )
635+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
560636 )
561- return unsafe extracting ( unchecked: range)
637+ return unsafe _ consumingExtracting ( unchecked: range)
562638 }
563639
564640 /// Constructs a new span over all the items of this span.
@@ -572,10 +648,23 @@ extension MutableRawSpan {
572648 /// - Complexity: O(1)
573649 @_alwaysEmitIntoClient
574650 @lifetime ( & self )
575- mutating public func extracting ( _: UnboundedRange ) -> Self {
651+ mutating public func _mutatingExtracting ( _: UnboundedRange ) -> Self {
576652 let newSpan = unsafe Self( _unchecked: _pointer, byteCount: _count)
577653 return unsafe _override Lifetime ( newSpan, mutating: & self )
578654 }
655+
656+ @available ( * , deprecated, renamed: " _mutatingExtracting(_:) " )
657+ @_alwaysEmitIntoClient
658+ @lifetime ( & self )
659+ mutating public func extracting( _: UnboundedRange ) -> Self {
660+ _mutatingExtracting ( ... )
661+ }
662+
663+ @_alwaysEmitIntoClient
664+ @lifetime ( copy self)
665+ consuming public func _consumingExtracting( _: UnboundedRange ) -> Self {
666+ self
667+ }
579668}
580669
581670// MARK: prefixes and suffixes
@@ -600,7 +689,7 @@ extension MutableRawSpan {
600689 /// - Complexity: O(1)
601690 @_alwaysEmitIntoClient
602691 @lifetime ( & self )
603- mutating public func extracting ( first maxLength: Int ) -> Self {
692+ mutating public func _mutatingExtracting ( first maxLength: Int ) -> Self {
604693#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
605694 _precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
606695 let newCount = min ( maxLength, byteCount)
@@ -611,6 +700,26 @@ extension MutableRawSpan {
611700#endif
612701 }
613702
703+ @available ( * , deprecated, renamed: " _mutatingExtracting(first:) " )
704+ @_alwaysEmitIntoClient
705+ @lifetime ( & self )
706+ mutating public func extracting( first maxLength: Int ) -> Self {
707+ _mutatingExtracting ( first: maxLength)
708+ }
709+
710+ @_alwaysEmitIntoClient
711+ @lifetime ( copy self)
712+ consuming public func _consumingExtracting( first maxLength: Int ) -> Self {
713+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
714+ _precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
715+ let newCount = min ( maxLength, byteCount)
716+ let newSpan = unsafe Self( _unchecked: _pointer, byteCount: newCount)
717+ return unsafe _override Lifetime ( newSpan, copying: self )
718+ #else
719+ fatalError ( " Unsupported compiler " )
720+ #endif
721+ }
722+
614723 /// Returns a span over all but the given number of trailing elements.
615724 ///
616725 /// If the number of elements to drop exceeds the number of elements in
@@ -627,7 +736,7 @@ extension MutableRawSpan {
627736 /// - Complexity: O(1)
628737 @_alwaysEmitIntoClient
629738 @lifetime ( & self )
630- mutating public func extracting ( droppingLast k: Int ) -> Self {
739+ mutating public func _mutatingExtracting ( droppingLast k: Int ) -> Self {
631740#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
632741 _precondition ( k >= 0 , " Can't drop a negative number of elements " )
633742 let droppedCount = min ( k, byteCount)
@@ -639,6 +748,27 @@ extension MutableRawSpan {
639748#endif
640749 }
641750
751+ @available ( * , deprecated, renamed: " _mutatingExtracting(droppingLast:) " )
752+ @_alwaysEmitIntoClient
753+ @lifetime ( & self )
754+ mutating public func extracting( droppingLast k: Int ) -> Self {
755+ _mutatingExtracting ( droppingLast: k)
756+ }
757+
758+ @_alwaysEmitIntoClient
759+ @lifetime ( copy self)
760+ consuming public func _consumingExtracting( droppingLast k: Int ) -> Self {
761+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
762+ _precondition ( k >= 0 , " Can't drop a negative number of elements " )
763+ let droppedCount = min ( k, byteCount)
764+ let newCount = byteCount &- droppedCount
765+ let newSpan = unsafe Self( _unchecked: _pointer, byteCount: newCount)
766+ return unsafe _override Lifetime ( newSpan, copying: self )
767+ #else
768+ fatalError ( " Unsupported compiler " )
769+ #endif
770+ }
771+
642772 /// Returns a span containing the final elements of the span,
643773 /// up to the given maximum length.
644774 ///
@@ -656,12 +786,37 @@ extension MutableRawSpan {
656786 /// - Complexity: O(1)
657787 @_alwaysEmitIntoClient
658788 @lifetime ( & self )
789+ mutating public func _mutatingExtracting( last maxLength: Int ) -> Self {
790+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
791+ _precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
792+ let newCount = min ( maxLength, byteCount)
793+ let newStart = unsafe _pointer? . advanced ( by: byteCount &- newCount)
794+ let newSpan = unsafe Self( _unchecked: newStart, byteCount: newCount)
795+ return unsafe _override Lifetime ( newSpan, mutating: & self )
796+ #else
797+ fatalError ( " Unsupported compiler " )
798+ #endif
799+ }
800+
801+ @available ( * , deprecated, renamed: " _mutatingExtracting(last:) " )
802+ @_alwaysEmitIntoClient
803+ @lifetime ( & self )
659804 mutating public func extracting( last maxLength: Int ) -> Self {
805+ _mutatingExtracting ( last: maxLength)
806+ }
807+
808+ @_alwaysEmitIntoClient
809+ @lifetime ( copy self)
810+ consuming public func _consumingExtracting( last maxLength: Int ) -> Self {
811+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
660812 _precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
661813 let newCount = min ( maxLength, byteCount)
662814 let newStart = unsafe _pointer? . advanced ( by: byteCount &- newCount)
663815 let newSpan = unsafe Self( _unchecked: newStart, byteCount: newCount)
664816 return unsafe _override Lifetime ( newSpan, copying: self )
817+ #else
818+ fatalError ( " Unsupported compiler " )
819+ #endif
665820 }
666821
667822 /// Returns a span over all but the given number of initial elements.
@@ -680,7 +835,7 @@ extension MutableRawSpan {
680835 /// - Complexity: O(1)
681836 @_alwaysEmitIntoClient
682837 @lifetime ( & self )
683- mutating public func extracting ( droppingFirst k: Int ) -> Self {
838+ mutating public func _mutatingExtracting ( droppingFirst k: Int ) -> Self {
684839#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
685840 _precondition ( k >= 0 , " Can't drop a negative number of bytes " )
686841 let droppedCount = min ( k, byteCount)
@@ -690,6 +845,28 @@ extension MutableRawSpan {
690845 return unsafe _override Lifetime ( newSpan, mutating: & self )
691846#else
692847 fatalError ( " Unsupported compiler " )
848+ #endif
849+ }
850+
851+ @available ( * , deprecated, renamed: " _mutatingExtracting(droppingFirst:) " )
852+ @_alwaysEmitIntoClient
853+ @lifetime ( & self )
854+ mutating public func extracting( droppingFirst k: Int ) -> Self {
855+ _mutatingExtracting ( droppingFirst: k)
856+ }
857+
858+ @_alwaysEmitIntoClient
859+ @lifetime ( copy self)
860+ consuming public func _consumingExtracting( droppingFirst k: Int ) -> Self {
861+ #if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
862+ _precondition ( k >= 0 , " Can't drop a negative number of bytes " )
863+ let droppedCount = min ( k, byteCount)
864+ let newStart = unsafe _pointer? . advanced ( by: droppedCount)
865+ let newCount = byteCount &- droppedCount
866+ let newSpan = unsafe Self( _unchecked: newStart, byteCount: newCount)
867+ return unsafe _override Lifetime ( newSpan, copying: self )
868+ #else
869+ fatalError ( " Unsupported compiler " )
693870#endif
694871 }
695872}
0 commit comments