File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -583,6 +583,18 @@ extension Unsafe${Mutable}BufferPointer where Element: ~Copyable {
583
583
return unsafe _override Lifetime ( span, borrowing: self )
584
584
}
585
585
}
586
+ % if Mutable:
587
+
588
+ @unsafe
589
+ @available ( SwiftStdlib 6 . 2 , * )
590
+ public var mutableSpan : MutableSpan < Element > {
591
+ @lifetime ( borrow self)
592
+ @_alwaysEmitIntoClient
593
+ get {
594
+ unsafe MutableSpan( _unsafeElements: self )
595
+ }
596
+ }
597
+ % end
586
598
}
587
599
588
600
extension Unsafe${ Mutable} BufferPointer {
Original file line number Diff line number Diff line change @@ -720,3 +720,25 @@ suite.test("extracting suffixes")
720
720
expectEqual ( span. extracting ( droppingFirst: 1 ) . count, b. count)
721
721
}
722
722
}
723
+
724
+ suite. test ( " MutableSpan from UnsafeMutableBufferPointer " )
725
+ . require ( . stdlib_6_2) . code {
726
+ guard #available( SwiftStdlib 6 . 2 , * ) else { return }
727
+
728
+ let capacity = 4
729
+ let b = UnsafeMutableBufferPointer< Int> . allocate( capacity: capacity)
730
+ defer {
731
+ b. deallocate ( )
732
+ }
733
+ _ = b. initialize ( fromContentsOf: 0 ..< capacity)
734
+
735
+ var span = b. mutableSpan
736
+ expectEqual ( span. count, capacity)
737
+
738
+ span. swapAt ( 0 , 3 )
739
+ span. swapAt ( 1 , 2 )
740
+
741
+ _ = consume span
742
+
743
+ expectTrue ( b. elementsEqual ( ( 0 ..< capacity) . reversed ( ) ) )
744
+ }
You can’t perform that action at this time.
0 commit comments