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

Handle modification during delete_if iteration #6393

Merged
merged 2 commits into from Sep 16, 2020

Conversation

headius
Copy link
Member

@headius headius commented Sep 16, 2020

In #6371 we saw that adding elements to the array while doing a delete_if iteration would end up skipping later elements. This was due to us memoizing the initial length of the array; elements added during iteration did not increase this length, so we would stop iterating prematurely.

The fix here matches CRuby, acquiring the array's new length for each iteration.

A test is provided in the JRuby suite but not in ruby/spec, due to the unspecified nature of this behavior.

This allows adding to the array while iterating. Previously,
adding elements while iterating for delete_if would lose existing
elements at the end, as they get pushed beyond our memoized size.

This behavior is not specified, but we make a best effort to match
CRuby behavior. There will be no specs added for this.

Fixes jruby#6371
This is unspecified behavior, but because we try to match CRuby I
am adding a test to our suite.

See jruby#6371
@headius headius added this to the JRuby 9.2.14.0 milestone Sep 16, 2020
@headius headius merged commit 74c1c6a into jruby:master Sep 16, 2020
1 check was pending
@headius headius deleted the delete_if_with_modification branch September 16, 2020 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant