Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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
@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.

1 participant