RFR: 8281631: HashMap.putAll can cause redundant space waste [v5]

XenoAmess duke at openjdk.java.net
Fri Feb 11 19:25:19 UTC 2022


On Fri, 11 Feb 2022 17:10:43 GMT, XenoAmess <duke at openjdk.java.net> wrote:

>> 8281631: HashMap.putAll can cause redundant space waste
>
> XenoAmess has updated the pull request incrementally with one additional commit since the last revision:
> 
>   9072610: HashMap.putAll can cause redundant space waste

> > FWIW, (int) Math.ceil(expected / 0.75) and (int) ((expected * 4L + 2L) / 3L) would be equivalent.
> 
> No, they are not equivalent. If `expected` exceeds a certain value around 1.6bn, then the intermediate result using the second expression will be greater than Integer.MAX_VALUE. Casting this to `int` can result in a negative number.

> > FWIW, (int) Math.ceil(expected / 0.75) and (int) ((expected * 4L + 2L) / 3L) would be equivalent.

that is exactly why we added this check when it can reach such situation.


        if (size > (int) (Integer.MAX_VALUE * 0.75)) {
            return Integer.MAX_VALUE;
        }

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

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


More information about the core-libs-dev mailing list