RFR: 8282178: Replace simple iterations of Map.entrySet with Map.forEach calls

liach duke at openjdk.java.net
Thu Feb 24 00:36:09 UTC 2022


On Wed, 23 Feb 2022 23:50:49 GMT, PROgrm_JARvis <duke at openjdk.java.net> wrote:

>> Replaces simple `for (Map.Entry<K, V> entry : map.entrySet())` with `map.forEach((k, v) ->)` calls. This change is better for thread-safety and reduces allocation for some map implementations.
>> 
>> A more in-depth description of benefits is available at https://mail.openjdk.java.net/pipermail/core-libs-dev/2022-February/086201.html and at the JBS issue itself.
>> 
>> A [jmh comparison](https://jmh.morethan.io/?sources=https://gist.githubusercontent.com/liach/0c0f79f0c0b9b78f474d65cda2c5f7b5/raw/4f2a160c51164aefdfac6ab5a19bdbc8c65f5fcf/base-results.json,https://gist.githubusercontent.com/liach/0c0f79f0c0b9b78f474d65cda2c5f7b5/raw/4f2a160c51164aefdfac6ab5a19bdbc8c65f5fcf/head-results.json) on the performance of the existing `HashMapBench` shows that the performance of `putAll` for `HashMap` has not significantly changed.
>
> src/java.base/share/classes/java/util/AbstractMap.java line 881:
> 
>> 879:      * used before indy and lambda expressions are ready in initPhase1.
>> 880:      * Regular code can safely use {@code map::put} instead.
>> 881:      */
> 
> Looks like `@param <K>` and `@param <V>` are missing although Javadoc-comment is used.

This javadoc-style comment is designed like the javadoc for `jdk.internal.` packages or package-private elements in `java.` packages, which only talks about cautions and rationale for this class. It is not rendered in the generated API documentations and not a public API.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7601


More information about the core-libs-dev mailing list