Skip to content

Fix DataProtocol.lastRange(of:) (and cherry-pick Data.swift changes from the overlay) #2310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
return Int(length)
}
set(newValue) {
precondition(newValue <= MemoryLayout<Buffer>.size)
assert(newValue <= MemoryLayout<Buffer>.size)
length = UInt8(newValue)
}
}
Expand Down Expand Up @@ -810,7 +810,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
assert(subrange.upperBound <= MemoryLayout<Buffer>.size)
assert(count - (subrange.upperBound - subrange.lowerBound) + replacementLength <= MemoryLayout<Buffer>.size)
precondition(subrange.lowerBound <= length, "index \(subrange.lowerBound) is out of bounds of 0..<\(length)")
precondition(subrange.upperBound <= length, "index \(subrange.lowerBound) is out of bounds of 0..<\(length)")
precondition(subrange.upperBound <= length, "index \(subrange.upperBound) is out of bounds of 0..<\(length)")
let currentLength = count
let resultingLength = currentLength - (subrange.upperBound - subrange.lowerBound) + replacementLength
let shift = resultingLength - currentLength
Expand Down Expand Up @@ -2223,7 +2223,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl

@inlinable // This is @inlinable as trivially forwarding.
internal func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: Range<Int>) {
if range.upperBound - range.lowerBound == 0 { return }
if range.isEmpty { return }
_representation.copyBytes(to: pointer, from: range)
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/DataProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ extension DataProtocol {
}

public func lastRange<D: DataProtocol>(of data: D) -> Range<Index>? {
return self.firstRange(of: data, in: self.startIndex ..< self.endIndex)
return self.lastRange(of: data, in: self.startIndex ..< self.endIndex)
}

@discardableResult
Expand Down