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 {
118
118
///
119
119
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
120
120
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
+ }
122
125
}
123
126
124
127
private func _copyBytesHelper( to pointer: UnsafeMutablePointer < UInt8 > , from range: CountableRange < Index > ) {
@@ -176,8 +179,11 @@ public struct DispatchData : RandomAccessCollection {
176
179
177
180
guard !copyRange. isEmpty else { return 0 }
178
181
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
+ }
181
187
return copyRange. count
182
188
}
183
189
You can’t perform that action at this time.
0 commit comments