@@ -482,13 +482,31 @@ extension MutableRawSpan {
482
482
/// - Complexity: O(1)
483
483
@_alwaysEmitIntoClient
484
484
@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 )
485
497
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 {
486
504
_precondition (
487
505
UInt ( bitPattern: bounds. lowerBound) <= UInt ( bitPattern: _count) &&
488
506
UInt ( bitPattern: bounds. upperBound) <= UInt ( bitPattern: _count) ,
489
507
" Index range out of bounds "
490
508
)
491
- return unsafe extracting ( unchecked: bounds)
509
+ return unsafe _ consumingExtracting ( unchecked: bounds)
492
510
}
493
511
494
512
/// Constructs a new span over the items within the supplied range of
@@ -509,12 +527,29 @@ extension MutableRawSpan {
509
527
@unsafe
510
528
@_alwaysEmitIntoClient
511
529
@lifetime ( & self )
512
- mutating public func extracting ( unchecked bounds: Range < Int > ) -> Self {
530
+ mutating public func _mutatingExtracting ( unchecked bounds: Range < Int > ) -> Self {
513
531
let newStart = unsafe _pointer? . advanced ( by: bounds. lowerBound)
514
532
let newSpan = unsafe Self( _unchecked: newStart, byteCount: bounds. count)
515
533
return unsafe _override Lifetime ( newSpan, mutating: & self )
516
534
}
517
535
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
+
518
553
/// Constructs a new span over the items within the supplied range of
519
554
/// positions within this span.
520
555
///
@@ -530,10 +565,27 @@ extension MutableRawSpan {
530
565
/// - Complexity: O(1)
531
566
@_alwaysEmitIntoClient
532
567
@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 )
533
577
mutating public func extracting(
534
578
_ bounds: some RangeExpression < Int >
535
579
) -> 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) )
537
589
}
538
590
539
591
/// Constructs a new span over the items within the supplied range of
@@ -554,11 +606,35 @@ extension MutableRawSpan {
554
606
@unsafe
555
607
@_alwaysEmitIntoClient
556
608
@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 {
558
634
let range = unsafe Range(
559
- _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound+ 1 )
635
+ _uncheckedBounds: ( bounds. lowerBound, bounds. upperBound + 1 )
560
636
)
561
- return unsafe extracting ( unchecked: range)
637
+ return unsafe _ consumingExtracting ( unchecked: range)
562
638
}
563
639
564
640
/// Constructs a new span over all the items of this span.
@@ -572,10 +648,23 @@ extension MutableRawSpan {
572
648
/// - Complexity: O(1)
573
649
@_alwaysEmitIntoClient
574
650
@lifetime ( & self )
575
- mutating public func extracting ( _: UnboundedRange ) -> Self {
651
+ mutating public func _mutatingExtracting ( _: UnboundedRange ) -> Self {
576
652
let newSpan = unsafe Self( _unchecked: _pointer, byteCount: _count)
577
653
return unsafe _override Lifetime ( newSpan, mutating: & self )
578
654
}
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
+ }
579
668
}
580
669
581
670
// MARK: prefixes and suffixes
@@ -600,7 +689,7 @@ extension MutableRawSpan {
600
689
/// - Complexity: O(1)
601
690
@_alwaysEmitIntoClient
602
691
@lifetime ( & self )
603
- mutating public func extracting ( first maxLength: Int ) -> Self {
692
+ mutating public func _mutatingExtracting ( first maxLength: Int ) -> Self {
604
693
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
605
694
_precondition ( maxLength >= 0 , " Can't have a prefix of negative length " )
606
695
let newCount = min ( maxLength, byteCount)
@@ -611,6 +700,26 @@ extension MutableRawSpan {
611
700
#endif
612
701
}
613
702
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
+
614
723
/// Returns a span over all but the given number of trailing elements.
615
724
///
616
725
/// If the number of elements to drop exceeds the number of elements in
@@ -627,7 +736,7 @@ extension MutableRawSpan {
627
736
/// - Complexity: O(1)
628
737
@_alwaysEmitIntoClient
629
738
@lifetime ( & self )
630
- mutating public func extracting ( droppingLast k: Int ) -> Self {
739
+ mutating public func _mutatingExtracting ( droppingLast k: Int ) -> Self {
631
740
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
632
741
_precondition ( k >= 0 , " Can't drop a negative number of elements " )
633
742
let droppedCount = min ( k, byteCount)
@@ -639,6 +748,27 @@ extension MutableRawSpan {
639
748
#endif
640
749
}
641
750
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
+
642
772
/// Returns a span containing the final elements of the span,
643
773
/// up to the given maximum length.
644
774
///
@@ -656,12 +786,37 @@ extension MutableRawSpan {
656
786
/// - Complexity: O(1)
657
787
@_alwaysEmitIntoClient
658
788
@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 )
659
804
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)
660
812
_precondition ( maxLength >= 0 , " Can't have a suffix of negative length " )
661
813
let newCount = min ( maxLength, byteCount)
662
814
let newStart = unsafe _pointer? . advanced ( by: byteCount &- newCount)
663
815
let newSpan = unsafe Self( _unchecked: newStart, byteCount: newCount)
664
816
return unsafe _override Lifetime ( newSpan, copying: self )
817
+ #else
818
+ fatalError ( " Unsupported compiler " )
819
+ #endif
665
820
}
666
821
667
822
/// Returns a span over all but the given number of initial elements.
@@ -680,7 +835,7 @@ extension MutableRawSpan {
680
835
/// - Complexity: O(1)
681
836
@_alwaysEmitIntoClient
682
837
@lifetime ( & self )
683
- mutating public func extracting ( droppingFirst k: Int ) -> Self {
838
+ mutating public func _mutatingExtracting ( droppingFirst k: Int ) -> Self {
684
839
#if compiler(>=5.3) && hasFeature(SendableCompletionHandlers)
685
840
_precondition ( k >= 0 , " Can't drop a negative number of bytes " )
686
841
let droppedCount = min ( k, byteCount)
@@ -690,6 +845,28 @@ extension MutableRawSpan {
690
845
return unsafe _override Lifetime ( newSpan, mutating: & self )
691
846
#else
692
847
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 " )
693
870
#endif
694
871
}
695
872
}
0 commit comments