-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8267452: Delegate forEachRemaining in Spliterators.iterator() #4124
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
Conversation
👋 Welcome back tvaleev! A progress list of the required criteria for merging this PR into |
Webrevs
|
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.
Changes look good.
Testing wise we have the combo test SpliteratorTraversingAndSplittingTest
that includes a case that tests a Spliterator produced via Spliterator -> Iterator -> Spliterator, and operations on that under various actions. GIven that case do you still think we require explicit tests?
@PaulSandoz thanks for review! As for
In short, it doesn't pass manual mutation testing. New tests are capable to catch more possible regressions. |
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.
Oops i missed the bit about testing in the description. That's subtle, the hasNext
occurs in the assert before the forEachRemaining
. Could you add a comment that this is the primary purpose of the test since SpliteratorTraversingAndSplittingTest
cannot do that for a spliterator wrapping an iterator?
@amaembo This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 74 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@PaulSandoz added a comment, thanks! |
/integrate |
@amaembo Since your change was applied there have been 74 commits pushed to the
Your commit was automatically rebased without conflicts. Pushed as commit ac36b7d. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Sometimes,
Spliterator::forEachRemaining
has much more optimized implementation, compared toSpliterator::tryAdvance
. For example, if aStream::spliterator
called for a stream that has intermediate operations,tryAdvance()
may buffer intermediate elements whileforEachRemaining()
just delegates to thewrapAndCopyInto
(seeStreamSpliterators.AbstractWrappingSpliterator
and its inheritors).Spliterators::iterator
methods (used in particular byStream::iterator
) provide adapter iterators that delegate to the supplied spliterator. Unfortunately, they don't have a specialized implementation forIterator::forEachRemaining
. As a result, a default implementation is used that delegates tohasNext
/next
, which in turn causes the delegation totryAdvance
. It's quite simple to implementIterator::forEachRemaining
here, taking advantage of possible spliterator optimizations if the iterator client decides to useforEachRemaining
.This patch implements Iterator::forEachRemaining in Spliterators::iterator methods. Also, I nullize the
nextElement
inIterator::next
to avoid accidental prolongation of the user's object lifetime when iteration is finished. Finally, a small cleanup: I added thefinal
modifier where possible to private fields inSpliterators
.Test-wise, some scenarios are already covered by SpliteratorTraversingAndSplittingTest. However, the resulting iterator is always wrapped into
Spliterators::spliterator
, so usage scenarios are somewhat limited. In particular, callinghasNext
(withoutnext
) beforeforEachRemaining
was not covered there. I added more tests inIteratorFromSpliteratorTest
to cover these scenarios. I checked that removingvalueReady = false;
oraction.accept(t);
lines from newly implementedforEachRemaining
method causes new tests to fail (but old tests don't fail due to this).Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4124/head:pull/4124
$ git checkout pull/4124
Update a local copy of the PR:
$ git checkout pull/4124
$ git pull https://git.openjdk.java.net/jdk pull/4124/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 4124
View PR using the GUI difftool:
$ git pr show -t 4124
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4124.diff