Skip to content

Eliminate 'instanceof' checks for FSTFieldValue #2651

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 5 commits into from
Mar 27, 2019
Merged

Conversation

rsgowman
Copy link
Member

@rsgowman rsgowman commented Mar 26, 2019

Previously, we checked for FSTFieldValue subtypes via:
[value isKindOfClass:[FSTStringValue class]]

Now, we check via a new type parameter on FSTFieldValue, i.e.:
[value type] == FSTFieldValueTypeString

This should enable easier transition to C++.

(Slightly) more context: go/firestore-cpp-fieldvalue

Will be used instead of isKindOfClass for RTTI to ease migration to c++.
@rsgowman rsgowman self-assigned this Mar 26, 2019
* The 'type' of this FSTFieldValue. Used for RTTI (rather than isKindOfClass)
* to ease migration to C++.
*/
typedef NS_ENUM(NSInteger, FSTFieldValueType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we wouldn't create this, but instead just use model::FieldValue::Type https://github.com/firebase/firebase-ios-sdk/blob/master/Firestore/core/src/firebase/firestore/model/field_value.h#L66

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I was going to do that conversion as part of step two... but it would be pointless. Fixed.

Previously, we checked for FSTFieldValue subtypes via:
`[value isKindOfClass:[FSTStringValue class]]`

Now, we check via a new type parameter on FSTFieldValue, i.e.:
`[value type] == FSTFieldValueTypeString`

This should enable easier transition to C++.
@rsgowman rsgowman requested a review from wilhuff March 26, 2019 22:16
@rsgowman rsgowman assigned wilhuff and unassigned rsgowman Mar 26, 2019
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -225,26 +238,24 @@ - (FSTTypeOrder)typeOrder {
}

- (NSComparisonResult)compare:(FSTFieldValue *)other {
if (![other isKindOfClass:[FSTNumberValue class]]) {
if (!([other type] == FieldValue::Type::Integer || [other type] == FieldValue::Type::Double)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe extract this into a static bool FieldValue::IsNumber(Type)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

* Returns the 'type' of this FSTFieldValue. Used for RTTI (rather than isKindOfClass)
* to ease migration to C++.
*/
- (firebase::firestore::model::FieldValue::Type)type;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to insert a using firebase::firestore::model::FieldValue in here to keep usage concise.

Also, FYI if you declared this as

@property(nonatomic, assign, readonly) FieldValue::Type type;

And then added @dynamic type; to the @implementation your existing implementation would look like a property that you could access as value.type (without creating a useless ivar).

This isn't going to be around for long so I don't insist at all.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. However, I roughly modelled the 'type' parameter after 'typeOrder', so I assume the same should be done to typeOrder. It turns out, typeOrder was already being used as as value.type, but lacked the @dynamic. So I added that. PTAL to ensure that makes sense.

@wilhuff wilhuff assigned rsgowman and unassigned wilhuff Mar 26, 2019
@rsgowman rsgowman assigned wilhuff and unassigned rsgowman Mar 27, 2019
@rsgowman rsgowman requested a review from wilhuff March 27, 2019 14:41
Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rsgowman rsgowman merged commit 6e5221b into master Mar 27, 2019
@rsgowman rsgowman deleted the rsgowman/fstfv branch March 27, 2019 16:26
Corrob pushed a commit that referenced this pull request Apr 25, 2019
Previously, we checked for FSTFieldValue subtypes via:
`[value isKindOfClass:[FSTStringValue class]]`

Now, we check via a new type parameter on FSTFieldValue, i.e.:
`value.type == firebase::firestore::model::FieldValue::Type::String`

Or with the appropriate using declaration:
`value.type == FieldValue::Type::String`

This should enable easier transition to C++.
@firebase firebase locked and limited conversation to collaborators Oct 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants