File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,10 @@ public struct DispatchData : RandomAccessCollection {
118118 ///
119119 /// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
120120 public mutating func append< SourceType> ( _ buffer : UnsafeBufferPointer < SourceType > ) {
121- self . append ( UnsafePointer ( buffer. baseAddress!) , count: buffer. count * sizeof( SourceType . self) )
121+ let count = buffer. count * sizeof( SourceType . self)
122+ buffer. baseAddress? . withMemoryRebound ( to: UInt8 . self, capacity: count) {
123+ self . append ( $0, count: count)
124+ }
122125 }
123126
124127 private func _copyBytesHelper( to pointer: UnsafeMutablePointer < UInt8 > , from range: CountableRange < Index > ) {
@@ -176,8 +179,11 @@ public struct DispatchData : RandomAccessCollection {
176179
177180 guard !copyRange. isEmpty else { return 0 }
178181
179- let pointer : UnsafeMutablePointer < UInt8 > = UnsafeMutablePointer < UInt8 > ( buffer. baseAddress!)
180- _copyBytesHelper ( to: pointer, from: copyRange)
182+ let bufferCapacity = buffer. count * sizeof( DestinationType . self)
183+ buffer. baseAddress? . withMemoryRebound ( to: UInt8 . self, capacity: bufferCapacity) {
184+
185+ _copyBytesHelper ( to: $0, from: copyRange)
186+ }
181187 return copyRange. count
182188 }
183189
You can’t perform that action at this time.
0 commit comments