Skip to content

Commit a63df4d

Browse files
committed
[gardening][(JSON|Plist)Encoder] Prefer !isEmpty over count > 0
1 parent b04155b commit a63df4d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

stdlib/public/SDK/Foundation/JSONEncoder.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ open class JSONEncoder {
110110
case custom((_ codingPath: [CodingKey]) -> CodingKey)
111111

112112
fileprivate static func _convertToSnakeCase(_ stringKey: String) -> String {
113-
guard stringKey.count > 0 else { return stringKey }
113+
guard !stringKey.isEmpty else { return stringKey }
114114

115115
var words : [Range<String.Index>] = []
116116
// The general idea of this algorithm is to split words on transition from lower to upper case, then on transition of >1 upper case characters to lowercase
@@ -351,7 +351,7 @@ fileprivate struct _JSONEncodingStorage {
351351
}
352352

353353
fileprivate mutating func popContainer() -> NSObject {
354-
precondition(self.containers.count > 0, "Empty container stack.")
354+
precondition(!self.containers.isEmpty, "Empty container stack.")
355355
return self.containers.popLast()!
356356
}
357357
}
@@ -1197,7 +1197,7 @@ fileprivate struct _JSONDecodingStorage {
11971197
}
11981198

11991199
fileprivate var topContainer: Any {
1200-
precondition(self.containers.count > 0, "Empty container stack.")
1200+
precondition(!self.containers.isEmpty, "Empty container stack.")
12011201
return self.containers.last!
12021202
}
12031203

@@ -1206,7 +1206,7 @@ fileprivate struct _JSONDecodingStorage {
12061206
}
12071207

12081208
fileprivate mutating func popContainer() {
1209-
precondition(self.containers.count > 0, "Empty container stack.")
1209+
precondition(!self.containers.isEmpty, "Empty container stack.")
12101210
self.containers.removeLast()
12111211
}
12121212
}

stdlib/public/SDK/Foundation/PlistEncoder.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fileprivate struct _PlistEncodingStorage {
209209
}
210210

211211
fileprivate mutating func popContainer() -> NSObject {
212-
precondition(self.containers.count > 0, "Empty container stack.")
212+
precondition(!self.containers.isEmpty, "Empty container stack.")
213213
return self.containers.popLast()!
214214
}
215215
}
@@ -746,7 +746,7 @@ fileprivate struct _PlistDecodingStorage {
746746
}
747747

748748
fileprivate var topContainer: Any {
749-
precondition(self.containers.count > 0, "Empty container stack.")
749+
precondition(!self.containers.isEmpty, "Empty container stack.")
750750
return self.containers.last!
751751
}
752752

@@ -755,7 +755,7 @@ fileprivate struct _PlistDecodingStorage {
755755
}
756756

757757
fileprivate mutating func popContainer() {
758-
precondition(self.containers.count > 0, "Empty container stack.")
758+
precondition(!self.containers.isEmpty, "Empty container stack.")
759759
self.containers.removeLast()
760760
}
761761
}

0 commit comments

Comments
 (0)