-
Notifications
You must be signed in to change notification settings - Fork 17
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
Improve support for BigInt, enhance union type #166
base: master
Are you sure you want to change the base?
Conversation
Not sure why Linter is complaining. There is no changes in
|
I'd guess a new version of RuboCop got used that changed how it it applies that rule. You could add |
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.
Thank you for working on this! It certainly seems like a gap.
A question I have is if we can remove the #matched?
in favor of special casing integer handling in UnionType#find_index
since we really only need matched?
for integers.
@@ -76,9 +76,8 @@ def referenced_model_classes | |||
private | |||
|
|||
def find_index(value) | |||
# TODO: Cache this? |
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.
This can be a hot code path, so it would be nice to be able to cache this index lookup (i.e., build a cache from value.class
to union_index
). With this change, since we match on the value
itself, that cache isn't possible.
Additionally, the matched?
call adds overhead for all types, but we only need it for the case where value.is_a?(Integer)
. What do you think about special casing integer handling here?
def find_index(value)
if value.is_a?(::Integer)
if Avromatic::Model::Types::IntegerType.in_range?(value)
member_types.index(Avromatic::Model::Types::IntegerType)
end || if Avromatic::Model::Types::BigIntType.in_range?(value)
member_types.index(Avromatic::Model::Types::BigIntType)
end
else
# TODO: Cache this
member_types.find_index do |member_type|
member_type.value_classes.any? { |value_class| value.is_a?(value_class) }
end
end
end
This fix allows handling situations where int and long are present and covers issues like: