[PATCH] Re: Custom spliterator for Collections.nCopies(n, obj).stream()
Tagir F. Valeev
amaembo at gmail.com
Sat Aug 22 09:17:28 UTC 2015
PS> With reuse it becomes more compelling :-) In both cases of
PS> singleton/nCopies the spliterator characteristics can be the same
PS> and that of the already existing singleton spliterator implementation.
The only difference is the DISTINCT characteristic. I think it's good
to report it based on the list size, so
Collections.nCopies(1, obj).spliterator() can report DISTINCT as well.
PS> I would be happy to accept a patch (with tests, if existing tests
PS> do not cover this already, i suspect they might but we still need
PS> to check). Have you signed the OCA . If so i can accept a patch
PS> from you and publish as a webrev for review.
Here's my patch to the Collections class. Implementation of the
ConstantSpliterator is added, singletonSpliterator method now uses it
as well as CopiesList::spliterator. CopiesList::stream and
CopiesList::parallelStream methods are removed as unnecessary.
The resulting bytecode is roughly 750 bytes less after applying my
As for tests, it seems that
covers both singletonSpliterator and nCopies().spliterator() pretty
well. I checked that these tests succeed with my changes while failed
when some mistake in ConstantSpliterator is introduced. If you think
that more tests are necessary, please suggest what exactly should be
tested and where to put them.
With best regards,
More information about the core-libs-dev