-
Notifications
You must be signed in to change notification settings - Fork 67
SWIFT-268 Store bson_oid_t in ObjectId rather than creating one each time we need it #238
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
kmahar
left a comment
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.
code changes lgtm, couple questions
|
|
||
| /// Initializes an `ObjectId` from the provided `String`. Assumes that the given string is a valid ObjectId. | ||
| /// - SeeAlso: https://github.com/mongodb/specifications/blob/master/source/objectid.rst | ||
| public init(fromString oid: String) { |
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.
any opinions on whether we should keep this parameter label? I feel like just from is more in line with the rest of the driver, and the String isn't needed to disambiguate from the decodable initializer.
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.
I agree fromString should probably be replaced. In fact, I kind of think the entire initializer should be removed, and init?(ifValid: String) should be the only one, with the ifValid label being replaced with either from or hex or fromHex.
The libbson docs do not mention what happens if bson_oid_init_from_string is called with an invalid string, so I guess we can say it's undefined behavior. I really think we should minimize the amount of UB easily available through our API if at all possible. Thoughts?
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.
I like the idea of having a single failable initializer in the public API. that is consistent with how we handle Decimal128s.
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.
Refactored init?(ifValid: String) to just init?(_: String). Let me know if you think it'd be better with a label. Also, removed the un-failable init.
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.
I could go either way.... it might be useful as an indicator about the type of string, but maybe that's not that necessary.
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.
@mbroadst any strong opinions on this one? I feel like I could go either way too. The one benefit of doing it without a label is that it looks just like it would in the shell, though I doubt we generally make many driver design choices based on how the shell behaves.
kmahar
left a comment
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.
lgtm
SWIFT-268
As part of this update, I refactored the public
oidproperty onObjectIdthat returns the string representation tohex, which is more descriptive. It also aligns with Go driver'sHex()and Java driver'stoHexString().I also refactored
init(fromPointer:)toinit(copying:), similar to the memory leak fix refactors.