Skip to content

[gardening][(JSON|Plist)Encoder] Prefer !isEmpty over count > 0 #15335

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
Mar 20, 2018
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
8 changes: 4 additions & 4 deletions stdlib/public/SDK/Foundation/JSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ open class JSONEncoder {
case custom((_ codingPath: [CodingKey]) -> CodingKey)

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

var words : [Range<String.Index>] = []
// 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
Expand Down Expand Up @@ -351,7 +351,7 @@ fileprivate struct _JSONEncodingStorage {
}

fileprivate mutating func popContainer() -> NSObject {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.popLast()!
}
}
Expand Down Expand Up @@ -1197,7 +1197,7 @@ fileprivate struct _JSONDecodingStorage {
}

fileprivate var topContainer: Any {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.last!
}

Expand All @@ -1206,7 +1206,7 @@ fileprivate struct _JSONDecodingStorage {
}

fileprivate mutating func popContainer() {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
self.containers.removeLast()
}
}
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/SDK/Foundation/PlistEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ fileprivate struct _PlistEncodingStorage {
}

fileprivate mutating func popContainer() -> NSObject {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.popLast()!
}
}
Expand Down Expand Up @@ -746,7 +746,7 @@ fileprivate struct _PlistDecodingStorage {
}

fileprivate var topContainer: Any {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
return self.containers.last!
}

Expand All @@ -755,7 +755,7 @@ fileprivate struct _PlistDecodingStorage {
}

fileprivate mutating func popContainer() {
precondition(self.containers.count > 0, "Empty container stack.")
precondition(!self.containers.isEmpty, "Empty container stack.")
self.containers.removeLast()
}
}
Expand Down