RFR: 8302818: Optimize wrapper sets and immutable sets of Enums
Tingjun Yuan
duke at openjdk.org
Mon Feb 20 12:15:34 UTC 2023
On Thu, 9 Feb 2023 19:37:03 GMT, liach <duke at openjdk.org> wrote:
> Just curious, how does this enum set change affect the performance of construction of regular sets via Set.of calls?
See `ImmutableCollections.setFromArray`, it relies on the fact that `EnumSet.copyOf` will throw a `ClassCastException` if the elements are not enum constants of a same enum class. Trying to catch an exception is a bit expensive (so maybe I can optimize that).
> On the JBS there's https://bugs.openjdk.org/browse/JDK-8145048 which appears to fit your changes.
I only enhanced `EnumSet`, but not `EnumMap` (yet) so I don't think it fits my changes.
> Just took a peek again. Besides the critical error of not throwing IAE for duplicate inputs (which you should probably add new test cases for), I think the 2 implementations share the same `toArray` `hashCode`, and the `contains` logic can be pulled to call an abstract `contains(int ordinal)` instead.
@liach Thanks for reviewing. I've fixed the issues you've mentioned.
> Have you submitted an issue at https://bugreport.java.com/bugreport/ ? It will show up a few days later on the JBS. If not, I can create an issue on the JBS for you too as long as you provide a prompt.
No I haven't. Submit one for me please. Thanks!
-------------
PR: https://git.openjdk.org/jdk/pull/12498
More information about the core-libs-dev
mailing list