@@ -49,7 +49,6 @@ public struct DispatchData : RandomAccessCollection {
49
49
/// Initialize a `Data` with copied memory content.
50
50
///
51
51
/// - parameter bytes: A pointer to the memory. It will be copied.
52
- /// - parameter count: The number of bytes to copy.
53
52
public init ( bytes buffer: UnsafeBufferPointer < UInt8 > ) {
54
53
let d = dispatch_data_create ( buffer. baseAddress!, buffer. count, nil , _dispatch_data_destructor_default ( ) )
55
54
self . init ( data: d)
@@ -88,7 +87,7 @@ public struct DispatchData : RandomAccessCollection {
88
87
public func enumerateBytes(
89
88
block: ( _ buffer: UnsafeBufferPointer < UInt8 > , _ byteIndex: Int , _ stop: inout Bool ) -> Void )
90
89
{
91
- _swift_dispatch_data_apply ( __wrapped. __wrapped) { ( data : dispatch_data_t , offset: Int , ptr: UnsafeRawPointer , size: Int ) in
90
+ _swift_dispatch_data_apply ( __wrapped. __wrapped) { ( _ , offset: Int , ptr: UnsafeRawPointer , size: Int ) in
92
91
let bytePtr = ptr. bindMemory ( to: UInt8 . self, capacity: size)
93
92
let bp = UnsafeBufferPointer ( start: bytePtr, count: size)
94
93
var stop = false
@@ -124,7 +123,7 @@ public struct DispatchData : RandomAccessCollection {
124
123
}
125
124
}
126
125
127
- private func _copyBytesHelper( to pointer: UnsafeMutablePointer < UInt8 > , from range: CountableRange < Index > ) {
126
+ private func _copyBytesHelper( to pointer: UnsafeMutableRawPointer , from range: CountableRange < Index > ) {
128
127
var copiedCount = 0
129
128
_ = CDispatch . dispatch_data_apply ( __wrapped. __wrapped) { ( data: dispatch_data_t , offset: Int , ptr: UnsafeRawPointer , size: Int ) in
130
129
let limit = Swift . min ( ( range. endIndex - range. startIndex) - copiedCount, size)
@@ -179,10 +178,7 @@ public struct DispatchData : RandomAccessCollection {
179
178
180
179
guard !copyRange. isEmpty else { return 0 }
181
180
182
- let bufferCapacity = buffer. count * MemoryLayout< DestinationType> . stride
183
- buffer. baseAddress? . withMemoryRebound ( to: UInt8 . self, capacity: bufferCapacity) {
184
- _copyBytesHelper ( to: $0, from: copyRange)
185
- }
181
+ _copyBytesHelper ( to: buffer. baseAddress!, from: copyRange)
186
182
return copyRange. count
187
183
}
188
184
@@ -244,7 +240,7 @@ public struct DispatchData : RandomAccessCollection {
244
240
245
241
public struct DispatchDataIterator : IteratorProtocol , Sequence {
246
242
247
- /// Create an iterator over the given DisaptchData
243
+ /// Create an iterator over the given DispatchData
248
244
public init ( _data: DispatchData ) {
249
245
var ptr : UnsafeRawPointer ?
250
246
self . _count = 0
0 commit comments