@@ -28,6 +28,7 @@ public struct MutableSpan<Element: ~Copyable>
2828 @usableFromInline
2929 internal let _count : Int
3030
31+ @unsafe
3132 @_alwaysEmitIntoClient
3233 internal func _start( ) -> UnsafeMutableRawPointer {
3334 unsafe _pointer. _unsafelyUnwrappedUnchecked
@@ -447,7 +448,7 @@ extension MutableSpan where Element: BitwiseCopyable {
447448 _ body: ( _ buffer: UnsafeMutableRawBufferPointer ) throws ( E ) -> Result
448449 ) throws ( E ) -> Result {
449450 let bytes = unsafe UnsafeMutableRawBufferPointer(
450- start: ( _count == 0 ) ? nil : _start ( ) ,
451+ start: ( _count == 0 ) ? nil : _pointer ,
451452 count: _count & * MemoryLayout< Element> . stride
452453 )
453454 return try unsafe body( bytes )
@@ -462,6 +463,7 @@ extension MutableSpan {
462463 @_alwaysEmitIntoClient
463464 @lifetime( self: copy self)
464465 public mutating func update( repeating repeatedValue: consuming Element ) {
466+ guard !isEmpty else { return }
465467 unsafe _start( ) . withMemoryRebound ( to: Element . self, capacity: count) {
466468 unsafe $0. update ( repeating: repeatedValue, count: count)
467469 }
@@ -599,7 +601,7 @@ extension MutableSpan where Element: BitwiseCopyable {
599601 ) where Element: BitwiseCopyable {
600602 guard count > 0 else { return }
601603 // rebind _start manually in order to avoid assumptions about alignment.
602- let rp = _start ( ) . _rawValue
604+ let rp = unsafe _start( ) . _rawValue
603605 let binding = Builtin . bindMemory ( rp, count. _builtinWordValue, Element . self)
604606 let rebound = unsafe UnsafeMutablePointer< Element > ( rp)
605607 unsafe rebound. update ( repeating: repeatedValue, count: count)
@@ -796,7 +798,7 @@ extension MutableSpan where Element: ~Copyable {
796798 @_alwaysEmitIntoClient
797799 @lifetime ( & self )
798800 mutating public func extracting( _: UnboundedRange ) -> Self {
799- let newSpan = unsafe Self( _unchecked: _start ( ) , count: _count)
801+ let newSpan = unsafe Self( _unchecked: _pointer , count: _count)
800802 return unsafe _override Lifetime ( newSpan, mutating: & self )
801803 }
802804}
0 commit comments