RFR: 8281631: HashMap.putAll can cause redundant space waste
XenoAmess
duke at openjdk.java.net
Fri Feb 11 12:29:05 UTC 2022
On Fri, 11 Feb 2022 11:55:13 GMT, stefan-zobel <duke at openjdk.java.net> wrote:
> > I investigated most of the usages. They just give a size, and get a capacity, even not change the 0.75 So maybe we can use some int calculation to replace the 0.75, thus replace Math.ceil for such situations.
>
> FWIW, `(int) Math.ceil(expected / 0.75)` and `(int) ((expected * 4L + 2L) / 3L)` would be equivalent.
Yes, and `(int) ((expected * 4L + 2L) / 3L)` actually equals `(expected + (expected + 2) / 3)` IMO, thus even avoid cast to long.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7431
More information about the core-libs-dev
mailing list