Skip to content
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

Exit iterator when RubyHash#any? short-circuits #2568

Merged
merged 1 commit into from Feb 5, 2015
Merged

Conversation

@grddev
Copy link
Contributor

@grddev grddev commented Feb 5, 2015

Previously, if any? returned true early (or threw an exception) the hash would be marked as still iterating, and thus prevent updates.

Expressed in Ruby code, the following results in "can't add a new key into hash during iteration" errors:

h = {1 => 2}; h.any? { true }; h[2] = 1
h = {1 => 2}; h.any? { raise } rescue nil; h[2] = 1

I would have liked to put them into tests, but wasn't completely sure were would be most appropriate.

Previously, if `any?` returned true early (or threw an exception) the
hash would be marked as still iterating, and thus prevent updates.
enebo added a commit that referenced this pull request Feb 5, 2015
Exit iterator when `RubyHash#any?` short-circuits
@enebo enebo merged commit ba60fb5 into jruby:master Feb 5, 2015
@enebo enebo added this to the 9.0.0.0.pre2 milestone Feb 5, 2015
@enebo
Copy link
Member

@enebo enebo commented Feb 5, 2015

@grddev Could this be an issue for our 1.7 branch as well? for 1.8.7 or 1.9.3 support?

@grddev
Copy link
Contributor Author

@grddev grddev commented Feb 5, 2015

As far as I can see the Hash#any? implementation was added in 2a2806e, which seems to exist in the master branch only.

@enebo
Copy link
Member

@enebo enebo commented Feb 5, 2015

@grddev Great thanks for checking! I also looked and I think this was added specifically to Hash and used to just fall back to Enumerable impl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants