Skip to content

Commit 9ce3a25

Browse files
compnerdktopley-apple
authored andcommitted
swift: modernise some types (NFC)
Update the implementation to address the deprecation warnings from the newer swift compiler. This is meant to be an equivalent update (NFCI). Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
1 parent 1c1ad9c commit 9ce3a25

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/swift/Data.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import _SwiftDispatchOverlayShims
1616
public struct DispatchData : RandomAccessCollection {
1717
public typealias Iterator = DispatchDataIterator
1818
public typealias Index = Int
19-
public typealias Indices = DefaultRandomAccessIndices<DispatchData>
19+
public typealias Indices = DefaultIndices<DispatchData>
2020

2121
public static let empty: DispatchData = DispatchData(data: _swift_dispatch_data_empty())
2222

@@ -174,7 +174,7 @@ public struct DispatchData : RandomAccessCollection {
174174
}
175175
}
176176

177-
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
177+
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: Range<Index>) {
178178
var copiedCount = 0
179179
if range.isEmpty { return }
180180
let rangeSize = range.count
@@ -215,8 +215,8 @@ public struct DispatchData : RandomAccessCollection {
215215
/// - parameter pointer: A pointer to the buffer you wish to copy the bytes into.
216216
/// - parameter range: The range in the `Data` to copy.
217217
/// - warning: This method does not verify that the contents at pointer have enough space to hold the required number of bytes.
218-
@available(swift, deprecated: 4, message: "Use copyBytes(to: UnsafeMutableRawBufferPointer, from: CountableRange<Index>) instead")
219-
public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
218+
@available(swift, deprecated: 4, message: "Use copyBytes(to: UnsafeMutableRawBufferPointer, from: Range<Index>) instead")
219+
public func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: Range<Index>) {
220220
_copyBytesHelper(to: pointer, from: range)
221221
}
222222

@@ -225,7 +225,7 @@ public struct DispatchData : RandomAccessCollection {
225225
/// - parameter pointer: A pointer to the buffer you wish to copy the bytes into. The buffer must be large
226226
/// enough to hold `count` bytes.
227227
/// - parameter range: The range in the `Data` to copy.
228-
public func copyBytes(to pointer: UnsafeMutableRawBufferPointer, from range: CountableRange<Index>) {
228+
public func copyBytes(to pointer: UnsafeMutableRawBufferPointer, from range: Range<Index>) {
229229
assert(range.count <= pointer.count, "Buffer too small to copy \(range.count) bytes")
230230
guard pointer.baseAddress != nil else { return }
231231
_copyBytesHelper(to: pointer.baseAddress!, from: range)
@@ -238,11 +238,11 @@ public struct DispatchData : RandomAccessCollection {
238238
/// - parameter buffer: A buffer to copy the data into.
239239
/// - parameter range: A range in the data to copy into the buffer. If the range is empty, this function will return 0 without copying anything. If the range is nil, as much data as will fit into `buffer` is copied.
240240
/// - returns: Number of bytes copied into the destination buffer.
241-
public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: CountableRange<Index>? = nil) -> Int {
241+
public func copyBytes<DestinationType>(to buffer: UnsafeMutableBufferPointer<DestinationType>, from range: Range<Index>? = nil) -> Int {
242242
let cnt = count
243243
guard cnt > 0 else { return 0 }
244244

245-
let copyRange : CountableRange<Index>
245+
let copyRange : Range<Index>
246246
if let r = range {
247247
guard !r.isEmpty else { return 0 }
248248
precondition(r.startIndex >= 0)
@@ -275,14 +275,14 @@ public struct DispatchData : RandomAccessCollection {
275275
return ptr!.load(fromByteOffset: index - offset, as: UInt8.self)
276276
}
277277

278-
public subscript(bounds: Range<Int>) -> RandomAccessSlice<DispatchData> {
279-
return RandomAccessSlice(base: self, bounds: bounds)
278+
public subscript(bounds: Range<Int>) -> Slice<DispatchData> {
279+
return Slice(base: self, bounds: bounds)
280280
}
281281

282282
/// Return a new copy of the data in a specified range.
283283
///
284284
/// - parameter range: The range to copy.
285-
public func subdata(in range: CountableRange<Index>) -> DispatchData {
285+
public func subdata(in range: Range<Index>) -> DispatchData {
286286
let subrange = CDispatch.dispatch_data_create_subrange(
287287
__wrapped.__wrapped, range.startIndex, range.endIndex - range.startIndex)
288288
return DispatchData(data: subrange)
@@ -335,7 +335,7 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
335335

336336
/// Advance to the next element and return it, or `nil` if no next
337337
/// element exists.
338-
public mutating func next() -> DispatchData._Element? {
338+
public mutating func next() -> DispatchData.Element? {
339339
if _position == _count { return nil }
340340
let element = _ptr.load(fromByteOffset: _position, as: UInt8.self)
341341
_position = _position + 1

0 commit comments

Comments
 (0)