Skip to content

Commit 0f96baf

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents ca29f40 + 3767ac7 commit 0f96baf

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/swift/Data.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,16 @@ public struct DispatchData : RandomAccessCollection {
135135

136136
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
137137
var copiedCount = 0
138+
if range.isEmpty { return }
139+
let rangeSize = range.count
138140
_ = CDispatch.dispatch_data_apply(__wrapped.__wrapped) { (data: dispatch_data_t, offset: Int, ptr: UnsafeRawPointer, size: Int) in
139-
let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
140-
memcpy(pointer + copiedCount, ptr, limit)
141-
copiedCount += limit
142-
return copiedCount < (range.endIndex - range.startIndex)
141+
if offset >= range.endIndex { return false } // This region is after endIndex
142+
let copyOffset = range.startIndex > offset ? range.startIndex - offset : 0 // offset of first byte, in this region
143+
if copyOffset >= size { return true } // This region is before startIndex
144+
let count = Swift.min(rangeSize - copiedCount, size - copyOffset)
145+
memcpy(pointer + copiedCount, ptr + copyOffset, count)
146+
copiedCount += count
147+
return copiedCount < rangeSize
143148
}
144149
}
145150

src/swift/Private.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public func dispatch_data_copy_region(_ data: dispatch_data_t, _ location: Int,
110110
fatalError()
111111
}
112112

113-
@available(*, unavailable, renamed:"DispatchQueue.asynchronously(self:group:qos:flags:execute:)")
113+
@available(*, unavailable, renamed:"DispatchQueue.async(self:group:qos:flags:execute:)")
114114
public func dispatch_group_async(_ group: DispatchGroup, _ queue: DispatchQueue, _ block: @escaping () -> Void)
115115
{
116116
fatalError()
@@ -146,7 +146,7 @@ public func dispatch_apply(_ iterations: Int, _ queue: DispatchQueue, _ block: (
146146
fatalError()
147147
}
148148

149-
@available(*, unavailable, renamed:"DispatchQueue.asynchronously(self:execute:)")
149+
@available(*, unavailable, renamed:"DispatchQueue.async(self:execute:)")
150150
public func dispatch_async(_ queue: DispatchQueue, _ block: @escaping () -> Void)
151151
{
152152
fatalError()

0 commit comments

Comments
 (0)