RFR: 8371656: HashMap.putAll() optimizations [v3]
Rémi Forax
forax at openjdk.org
Wed Feb 11 18:59:32 UTC 2026
On Wed, 11 Feb 2026 13:47:17 GMT, jengebr <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/util/HashMap.java line 516:
>>
>>> 514: */
>>> 515: final void putMapEntries(Map<? extends K, ? extends V> m, boolean evict) {
>>> 516: if (m.getClass() == Collections.UnmodifiableMap.class) {
>>
>> I would address that issue in a separate bug.
>
> What issue? This is an integral part of the performance optimization.
Your PR proposes two optimizations,
- HashMap.putAll(HashMap)
- HashMap.putAll(UnmodifiableMap(HashMap))
The former have been done numerous time for other collections, the latter is as far as as know new.
There are several reasons to not wanting to do the latter , on top of my head:
- this is not a symmetrical transformation,
- why only have this optimization on HashMap and not ArrayList and/or ArrayDeque ?
So It's a separate issue that should be discussed on on the mailist list first.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28243#discussion_r2794933915
More information about the core-libs-dev
mailing list