RFR: 8327858: Improve spliterator and forEach for single-element immutable collections [v2]
Chen Liang
liach at openjdk.org
Thu Mar 21 19:28:22 UTC 2024
On Tue, 12 Mar 2024 10:12:18 GMT, Viktor Klang <vklang at openjdk.org> wrote:
>> Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 13 commits:
>>
>> - Use the improved form in forEach
>> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/imm-coll-stream
>> - Null checks should probably be in the beginning...
>> - mark implicit null checks
>> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/imm-coll-stream
>> - Copyright year, revert changes for non-few element collections
>> - Merge branch 'master' of https://github.com/openjdk/jdk into feature/imm-coll-stream
>> - Merge branch 'feature/imm-coll-stream' of https://github.com/liachmodded/jdk into feature/imm-coll-stream
>> - Spliterator for 12, iterate/forEach benchmark
>> - fix comments
>> - ... and 3 more: https://git.openjdk.org/jdk/compare/d5b95a0e...69bd0e9c
>
> src/java.base/share/classes/java/util/ImmutableCollections.java line 926:
>
>> 924: if (!REVERSE && e1 != EMPTY) {
>> 925: action.accept((E) e1);
>> 926: }
>
> I'm curious to know how the following alternative would fare:
>
> Suggestion:
>
> if (e1 != EMPTY) {
> action.accept(REVERSE ? (E)e1 : (E)e0); // implicit null check
> action.accept(REVERSE ? (E)e0 : (E)e1);
> } else {
> action.accept(e0); // Implicit null check
> }
@viktorklang-ora I've updated this piece of code, does it look better now?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15834#discussion_r1534539452
More information about the core-libs-dev
mailing list