On Wed, 22 Mar 2023 01:22:37 GMT, Tingjun Yuan <d...@openjdk.org> wrote:

>> Currently, the two subclasses of `java.util.EnumSet` optimize bulk 
>> operations when the argument is also a `EnumSet`, but there is no such 
>> optimization for wrapper sets (returned by `Collections.unmodifiableSet`, 
>> `Collections.synchronizedSet`, etc.) and immutable sets (returned by 
>> `Set.of` methods) of `Enum`s.
>> 
>> This PR introduces optimization classes for these situations.  No public 
>> APIs are changed.
>
> Tingjun Yuan has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Fix a whitespace error

The `Immutable*ESIterator.lastReturned*` fields can be made into locals of 
`Immutable*ESIterator::next()`, as the only reason those fields exist in 
`RegularEnumSet.EnumSetIterator` and `JumboEnumSet.EnumSetIterator` is to 
support `Iterator::remove()`, which is not a valid operation on immutable enum 
sets:

src/java.base/share/classes/java/util/ImmutableCollections.java line 1199:

> 1197:         private final class ImmutableRESIterator implements Iterator<E> 
> {
> 1198:             long unseen = elements;
> 1199:             long lastReturned = 0;

Suggestion:

src/java.base/share/classes/java/util/ImmutableCollections.java line 1212:

> 1210:                 if (unseen == 0)
> 1211:                     throw new NoSuchElementException();
> 1212:                 lastReturned = unseen & -unseen;

Suggestion:

                long lastReturned = unseen & -unseen;

src/java.base/share/classes/java/util/ImmutableCollections.java line 1299:

> 1297:             int unseenIndex = 0;
> 1298:             long lastReturned = 0;
> 1299:             int lastReturnedIndex = 0;

Suggestion:

src/java.base/share/classes/java/util/ImmutableCollections.java line 1315:

> 1313:                     throw new NoSuchElementException();
> 1314:                 lastReturned = unseen & -unseen;
> 1315:                 lastReturnedIndex = unseenIndex;

Suggestion:

                long lastReturned = unseen & -unseen;
                int lastReturnedIndex = unseenIndex;

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

PR Review: https://git.openjdk.org/jdk/pull/12498#pullrequestreview-1352706671
PR Review Comment: https://git.openjdk.org/jdk/pull/12498#discussion_r1144897096
PR Review Comment: https://git.openjdk.org/jdk/pull/12498#discussion_r1144897486
PR Review Comment: https://git.openjdk.org/jdk/pull/12498#discussion_r1144907088
PR Review Comment: https://git.openjdk.org/jdk/pull/12498#discussion_r1144909930

Reply via email to