RFR: 8302818: Optimize wrapper sets and immutable sets of Enums [v2]
liach
duke at openjdk.org
Mon Feb 20 14:00:28 UTC 2023
On Mon, 20 Feb 2023 13:24:27 GMT, Tingjun Yuan <duke at openjdk.org> wrote:
>> 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
>
>> Bad change, doesn't handle e0.equals(e1), and this is getting beyond the original issue
>
> `Set.of(E, E)` handles duplication. If `coll` is `{Jumbo,Regular}EnumSetCompatible`, then we don't have to create the `HashSet`.
no, Set.copyOf explicitly allows duplications, unlike Set.of. You need to read the specs so you know what you are doing.
-------------
PR: https://git.openjdk.org/jdk/pull/12498
More information about the core-libs-dev
mailing list