Skip to content

Commit b95e6bf

Browse files
committed
[gardening] Prefer isEmpty over count check
1 parent ffe450b commit b95e6bf

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Foundation/Data.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
15531553
/// - parameter buffer: The replacement bytes.
15541554
@inline(__always)
15551555
public mutating func replaceSubrange<SourceType>(_ subrange: Range<Index>, with buffer: UnsafeBufferPointer<SourceType>) {
1556-
guard buffer.count > 0 else { return }
1556+
guard !buffer.isEmpty else { return }
15571557
replaceSubrange(subrange, with: buffer.baseAddress!, count: buffer.count * MemoryLayout<SourceType>.stride)
15581558
}
15591559

@@ -1635,7 +1635,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
16351635
var hashValue = 0
16361636
let hashRange: Range<Int> = _sliceRange.lowerBound..<Swift.min(_sliceRange.lowerBound + 80, _sliceRange.upperBound)
16371637
_withStackOrHeapBuffer(hashRange.count + 1) { buffer in
1638-
if hashRange.count > 0 {
1638+
if !hashRange.isEmpty {
16391639
_backing.withUnsafeBytes(in: hashRange) {
16401640
memcpy(buffer.pointee.memory, $0.baseAddress!, hashRange.count)
16411641
}

Foundation/JSONEncoder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fileprivate struct _JSONEncodingStorage {
283283
}
284284

285285
fileprivate mutating func popContainer() -> NSObject {
286-
precondition(self.containers.count > 0, "Empty container stack.")
286+
precondition(!self.containers.isEmpty, "Empty container stack.")
287287
return self.containers.popLast()!
288288
}
289289
}
@@ -1001,7 +1001,7 @@ fileprivate struct _JSONDecodingStorage {
10011001
}
10021002

10031003
fileprivate var topContainer: Any {
1004-
precondition(self.containers.count > 0, "Empty container stack.")
1004+
precondition(!self.containers.isEmpty, "Empty container stack.")
10051005
return self.containers.last!
10061006
}
10071007

@@ -1010,7 +1010,7 @@ fileprivate struct _JSONDecodingStorage {
10101010
}
10111011

10121012
fileprivate mutating func popContainer() {
1013-
precondition(self.containers.count > 0, "Empty container stack.")
1013+
precondition(!self.containers.isEmpty, "Empty container stack.")
10141014
self.containers.removeLast()
10151015
}
10161016
}

Foundation/NSArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
653653
}
654654

655655
open func pathsMatchingExtensions(_ filterTypes: [String]) -> [String] {
656-
guard filterTypes.count > 0 else {
656+
guard !filterTypes.isEmpty else {
657657
return []
658658
}
659659

Foundation/UserDefaults.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ open class UserDefaults: NSObject {
301301

302302
let defaultsFromDiskWithNumbersBoxed = _SwiftValue.fetch(defaultsFromDiskCF) as? [String: Any] ?? [:]
303303

304-
if registeredDefaultsIfAllowed.count == 0 {
304+
if registeredDefaultsIfAllowed.isEmpty {
305305
return UserDefaults._unboxingNSNumbers(defaultsFromDiskWithNumbersBoxed) as! [String: Any]
306306
} else {
307307
var allDefaults = registeredDefaultsIfAllowed

0 commit comments

Comments
 (0)