diff --git a/Foundation/Data.swift b/Foundation/Data.swift index c9c1b2ee8b..5235408825 100644 --- a/Foundation/Data.swift +++ b/Foundation/Data.swift @@ -721,7 +721,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl return Int(length) } set(newValue) { - precondition(newValue <= MemoryLayout.size) + assert(newValue <= MemoryLayout.size) length = UInt8(newValue) } } @@ -810,7 +810,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl assert(subrange.upperBound <= MemoryLayout.size) assert(count - (subrange.upperBound - subrange.lowerBound) + replacementLength <= MemoryLayout.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 @@ -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) { - if range.upperBound - range.lowerBound == 0 { return } + if range.isEmpty { return } _representation.copyBytes(to: pointer, from: range) } diff --git a/Foundation/DataProtocol.swift b/Foundation/DataProtocol.swift index 77bc2eeeed..3e9f88cf22 100644 --- a/Foundation/DataProtocol.swift +++ b/Foundation/DataProtocol.swift @@ -80,7 +80,7 @@ extension DataProtocol { } public func lastRange(of data: D) -> Range? { - return self.firstRange(of: data, in: self.startIndex ..< self.endIndex) + return self.lastRange(of: data, in: self.startIndex ..< self.endIndex) } @discardableResult