RFR: 8366178: Implement JEP 526: Lazy Constants (Second Preview) [v20]
Per Minborg
pminborg at openjdk.org
Mon Nov 10 12:36:12 UTC 2025
On Wed, 5 Nov 2025 23:31:38 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Per Minborg has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Rework toString implementations
>
> src/java.base/share/classes/java/util/Map.java line 1814:
>
>> 1812: final Set<K> keyCopies = Set.copyOf(keys);
>> 1813: Objects.requireNonNull(computingFunction);
>> 1814: if (keys instanceof EnumSet<?> && !keys.isEmpty()) {
>
> I wonder if it's premature for us to optimize like this - for example, this would be wasteful if the key set contains one enum constant but there are 1000 enum constants in this enum.
There is a `min` and a `max` ordinal calculated, so in your example above, only one array item is used. I.e., if there are 1,000 enum constant and we are using enum with ordinal 42, then min = max = 42 and only a one-element array is ever allocated.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27605#discussion_r2510377932
More information about the core-libs-dev
mailing list