@@ -28,6 +28,7 @@ public struct MutableSpan<Element: ~Copyable>
28
28
@usableFromInline
29
29
internal let _count : Int
30
30
31
+ @unsafe
31
32
@_alwaysEmitIntoClient
32
33
internal func _start( ) -> UnsafeMutableRawPointer {
33
34
unsafe _pointer. _unsafelyUnwrappedUnchecked
@@ -447,7 +448,7 @@ extension MutableSpan where Element: BitwiseCopyable {
447
448
_ body: ( _ buffer: UnsafeMutableRawBufferPointer ) throws ( E ) -> Result
448
449
) throws ( E ) -> Result {
449
450
let bytes = unsafe UnsafeMutableRawBufferPointer(
450
- start: ( _count == 0 ) ? nil : _start ( ) ,
451
+ start: ( _count == 0 ) ? nil : _pointer ,
451
452
count: _count & * MemoryLayout< Element> . stride
452
453
)
453
454
return try unsafe body( bytes )
@@ -462,6 +463,7 @@ extension MutableSpan {
462
463
@_alwaysEmitIntoClient
463
464
@lifetime( self: copy self)
464
465
public mutating func update( repeating repeatedValue: consuming Element ) {
466
+ guard !isEmpty else { return }
465
467
unsafe _start( ) . withMemoryRebound ( to: Element . self, capacity: count) {
466
468
unsafe $0. update ( repeating: repeatedValue, count: count)
467
469
}
@@ -599,7 +601,7 @@ extension MutableSpan where Element: BitwiseCopyable {
599
601
) where Element: BitwiseCopyable {
600
602
guard count > 0 else { return }
601
603
// rebind _start manually in order to avoid assumptions about alignment.
602
- let rp = _start ( ) . _rawValue
604
+ let rp = unsafe _start( ) . _rawValue
603
605
let binding = Builtin . bindMemory ( rp, count. _builtinWordValue, Element . self)
604
606
let rebound = unsafe UnsafeMutablePointer< Element > ( rp)
605
607
unsafe rebound. update ( repeating: repeatedValue, count: count)
@@ -796,7 +798,7 @@ extension MutableSpan where Element: ~Copyable {
796
798
@_alwaysEmitIntoClient
797
799
@lifetime ( & self )
798
800
mutating public func extracting( _: UnboundedRange ) -> Self {
799
- let newSpan = unsafe Self( _unchecked: _start ( ) , count: _count)
801
+ let newSpan = unsafe Self( _unchecked: _pointer , count: _count)
800
802
return unsafe _override Lifetime ( newSpan, mutating: & self )
801
803
}
802
804
}
0 commit comments