-
Notifications
You must be signed in to change notification settings - Fork 185
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
Implement rb_hash_bulk_insert #3715
Implement rb_hash_bulk_insert #3715
Conversation
c40cf04
to
75f5120
Compare
I believe it's OK to have this overhead. |
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.
Good job!
hash.should == {a: 1, b: 2} | ||
end | ||
end | ||
|
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 would also add the following cases:
- length isn't even - there should be error raised (I suppose)
- how duplicated keys (provided in the array) are handled - I suppose they should just override each other
* What happens for duplicated keys? Well it silently discards older ones to
* accept the newest (rightmost) one. This behaviour also mimics repeated call
* of rb_hash_aset().
- it's allowed to pass NULL as array if length argument = 0 (as far as it's explicitly stated in a documentation comment
* @note `argv` is allowed to be NULL as long as `argc` is zero.
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'll add tests for the other cases.
As for when the length isn't even, it appears to be that if RUBY_DEBUG
is not defined MRI accepts an array with an odd number of elements and will read one past the end. Should we allow the same to maintain compatibility?
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.
Ah, right. Yes, it makes sense to do the same and to allow passing odd length.
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.
We shouldn't add a spec for that odd case, because specs should also pass with RUBY_DEBUG
, notably ruby-dev-builder
depends on that.
@andrykonchin Could you add a commit removing that spec?
We could file an issue at https://bugs.ruby-lang.org/, I think it would make sense, it doesn't seem OK the C API reads past the length it's given.
75f5120
to
f39d25d
Compare
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.
Looks good! Thank you.
f39d25d
to
529bd60
Compare
Closes #3705
In this case I'm not sure if the overhead of repeated calls to
[]=
makes it worth instead adding another method toCExtNodes.java