-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
@swift-ci Please smoke test |
@swift-ci smoke test |
The failure looks unrelated. @swift-ci Please clean smoke test Linux platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time to put this together; the change itself looks okay, but is there a concrete reason for the code churn?
@itaiferber I'm a fan of using /// The number of elements in the collection.
///
/// To check whether a collection is empty, use its `isEmpty` property
/// instead of comparing `count` to zero. Unless the collection guarantees
/// random-access performance, calculating `count` can be an O(*n*)
/// operation.
///
/// - Complexity: O(1) if the collection conforms to
/// `RandomAccessCollection`; otherwise, O(*n*), where *n* is the length
/// of the collection.
var count: Int { get } Or the doc comments is not right or is misleading? Is that only about For the cases in this PR the collections are random-access ones so there should be no differences actually, but using |
Ref: #15326 |
See also #12504 (comment) and #12638. |
Please let me know if I have overlooked something 😃 |
@itaiferber At the very least, changing the instance of |
From a correctness perspective, I don't disagree — it's just that our collections offer O(1) |
Please make a similar change over on https://github.com/apple/swift-corelibs-foundation, if you don't mind. |
No description provided.