RFR: 8327858: Improve spliterator and forEach for single-element immutable collections [v2]

ExE Boss duke at openjdk.org
Sun Apr 28 01:48:19 UTC 2024


On Fri, 26 Apr 2024 22:11:07 GMT, Chen Liang <liach at openjdk.org> wrote:

>> Do we need additional tests or are these modifications already covered by the existing tests?
>
> @minborg I have added a test as part of Collection mother-of-all-tests to ensure spliterator and forEach yields in the same order as iterator for unmodifiable/immutable collections. One thing of note is that somehow `==` for yields fail for some collections like `unmodifiableSequencedMap(linkedHashSet).sequencedKeySet()` so I have to use `Objects.equals` instead.

@liach
> One thing of note is that somehow `==` for yields fail for some collections like `unmodifiableSequencedMap(linkedHashSet)​.sequencedKeySet()` so I have to use `Objects.equals` instead.

Actually, it’d be for `unmodifiableMap(…)​.entrySet()` and `Map​.of(…)​.entrySet()`, as those create a new `UnmodifiableEntry` and `KeyValueHolder` on iteration respectively.

`unmodifiableSequencedMap(…)​.sequencedKeySet()` should work with `==`.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15834#issuecomment-2081284896


More information about the core-libs-dev mailing list