RFR: 8186958: Need method to create pre-sized HashMap [v7]

Chris Hegarty chegar at openjdk.java.net
Sat Mar 26 10:58:44 UTC 2022


On Thu, 24 Mar 2022 17:43:31 GMT, XenoAmess <duke at openjdk.java.net> wrote:

>> 8186958: Need method to create pre-sized HashMap
>
> XenoAmess has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - update jmh
>  - refine javadoc; refine implement when expectedSize < 0

This is a very nice addition. In Elasticsearch we have such API points, which are tedious to get right and test.

src/java.base/share/classes/java/util/HashMap.java line 2584:

> 2582: 
> 2583:     /**
> 2584:      * Creates a new, empty HashMap with an initial table size

You probably wanna allow for a non-NEW instance for the corner case where the given size is 0 - no elements.

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

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


More information about the core-libs-dev mailing list