On Mon, 20 Feb 2023 13:15:03 GMT, Tingjun Yuan <[email protected]> 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:
>
> Optimize `EnumSet.copyOf` and `Set.copyOf`
src/java.base/share/classes/java/util/EnumSet.java line 186:
> 184: } else {
> 185: while (i.hasNext())
> 186: result.add(i.next());
Can't we just use addAll in all cases?
src/java.base/share/classes/java/util/Set.java line 742:
> 740: E e1 = it.next();
> 741: if (!it.hasNext()) {
> 742: return Set.of(e0, e1);
Bad change, doesn't handle e0.equals(e1), and this is getting beyond the
original issue
-------------
PR: https://git.openjdk.org/jdk/pull/12498