Skip to content

Commit 0765871

Browse files
authored
Merge pull request swiftlang#1361 from ikesyo/prefer-isempty
[gardening] Prefer `isEmpty` over `count == 0`
2 parents 42c200d + 21b8064 commit 0765871

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

Diff for: Foundation/Data.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ public final class _DataStorage {
866866
}
867867

868868
public func withInteriorPointerReference<T>(_ range: Range<Int>, _ work: (NSData) throws -> T) rethrows -> T {
869-
if range.count == 0 {
869+
if range.isEmpty {
870870
return try work(NSData()) // zero length data can be optimized as a singleton
871871
}
872872

@@ -898,7 +898,7 @@ public final class _DataStorage {
898898
}
899899

900900
public func bridgedReference(_ range: Range<Int>) -> NSData {
901-
if range.count == 0 {
901+
if range.isEmpty {
902902
return NSData() // zero length data can be optimized as a singleton
903903
}
904904

@@ -1476,7 +1476,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
14761476
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
14771477
@inline(__always)
14781478
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
1479-
if buffer.count == 0 { return }
1479+
if buffer.isEmpty { return }
14801480
if !isKnownUniquelyReferenced(&_backing) {
14811481
_backing = _backing.mutableCopy(_sliceRange)
14821482
}
@@ -1606,7 +1606,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
16061606
@inline(__always)
16071607
public func subdata(in range: Range<Index>) -> Data {
16081608
_validateRange(range)
1609-
if count == 0 {
1609+
if isEmpty {
16101610
return Data()
16111611
}
16121612
return _backing.subdata(in: range)

Diff for: Foundation/URLSession/TaskRegistry.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ extension URLSession._TaskRegistry {
9292
}
9393

9494
var isEmpty: Bool {
95-
return tasks.count == 0
95+
return tasks.isEmpty
9696
}
9797
}
9898
extension URLSession._TaskRegistry {

Diff for: Foundation/XMLParser.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ internal func _NSXMLParserStartElementNs(_ ctx: _CFXMLInterface, localname: Unsa
282282
let attrLocalName = attributes[idx]!
283283
let attrLocalNameString = UTF8STRING(attrLocalName)!
284284
let attrPrefix = attributes[idx + 1]
285-
if let attrPrefixString = UTF8STRING(attrPrefix), attrPrefixString.count != 0 {
285+
if let attrPrefixString = UTF8STRING(attrPrefix), !attrPrefixString.isEmpty {
286286
attributeQName = attrPrefixString + ":" + attrLocalNameString
287287
} else {
288288
attributeQName = attrLocalNameString

Diff for: TestFoundation/TestNSString.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ class TestNSString : XCTestCase {
604604
var matches: [String] = []
605605
let count = path.completePath(into: &outName, caseSensitive: false, matchesInto: &matches, filterTypes: nil)
606606
XCTAssert(outName == "", "If no matches found then outName is nil.")
607-
XCTAssert(matches.count == 0 && count == 0, "If no matches found then return 0 and matches is empty.")
607+
XCTAssert(matches.isEmpty && count == 0, "If no matches found then return 0 and matches is empty.")
608608
}
609609

610610
do {
@@ -613,7 +613,7 @@ class TestNSString : XCTestCase {
613613
var matches: [String] = []
614614
let count = path.completePath(into: &outName, caseSensitive: false, matchesInto: &matches, filterTypes: nil)
615615
XCTAssert(outName == "", "If no matches found then outName is nil.")
616-
XCTAssert(matches.count == 0 && count == 0, "If no matches found then return 0 and matches is empty.")
616+
XCTAssert(matches.isEmpty && count == 0, "If no matches found then return 0 and matches is empty.")
617617
}
618618

619619
do {

0 commit comments

Comments
 (0)