RFR: 8281631: HashMap.putAll can cause redundant space waste [v3]
Roger Riggs
rriggs at openjdk.java.net
Fri Feb 11 15:07:08 UTC 2022
On Fri, 11 Feb 2022 13:04:38 GMT, XenoAmess <duke at openjdk.java.net> wrote:
>> 8281631: HashMap.putAll can cause redundant space waste
>
> XenoAmess has refreshed the contents of this pull request, and previous commits have been removed. The incremental views will show differences compared to the previous content of the PR. The pull request contains one new commit since the last revision:
>
> 9072610: HashMap.putAll can cause redundant space waste
src/java.base/share/classes/java/util/WeakHashMap.java line 247:
> 245: */
> 246: private static int calculateHashMapCapacity(int size){
> 247: return size + (size + 2) / 3;
Consider integer overflow; if size were Integer.MAX_VALUE / 2; the computation would overflow.
The negative result would eventually throw an exception. Using Long for the computation would avoid that and keep the expression simple.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7431
More information about the core-libs-dev
mailing list