RFR: 8362958: Unnecessary copying / sorting in Streams using Comparator.naturalOrder() [v4]
Patrick Strawderman
duke at openjdk.org
Tue Nov 11 20:59:20 UTC 2025
On Tue, 11 Nov 2025 18:15:04 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:
>> Patrick Strawderman has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Fix bad merge
>
> src/java.base/share/classes/java/util/stream/StreamOpFlag.java line 753:
>
>> 751: int characteristics = spliterator.characteristics();
>> 752: if ((characteristics & Spliterator.SORTED) != 0 &&
>> 753: (spliterator.getComparator() instanceof Comparator c &&
>
> Not sure if the performance of `instanceof` is meaningfully faster than `!=`, but the `instanceof` test could be replaced with a null test:
>
> if ((characteristics & Spliterator.SORTED) != 0) {
> Comparator<?> c = spliterator.getComparator();
> if (c != null && !c.equals(Comparator.naturalOrder()) { ...
I actually prefer this, seems a bit more readable to me. Thanks!
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28226#discussion_r2515785006
More information about the core-libs-dev
mailing list