On Fri, 2 Feb 2024 04:51:33 GMT, jmehrens <d...@openjdk.org> wrote: > Circling back to "the case where many keys exist in both maps". What are your > thoughts on some optimized variant/refactoring of: int s = Math.max(m.size() - this.size(), 1);
Calling `Math.max` is unnecessary here. Its ok if `s` ends up non-positive, presizing would become a no-op in that case. I don't understand why there is a subtraction. If `m` is a larger map than `this`, and has all of `this`'s keys, the resulting map will have the same size as `m`. In this case, we should just presize to `m.size()`. > Also, are we sure it is wise to actually call m.size() when we don't know the > runtime of the size operation on the given map? Not sure, but the current code already calls `m.size()`. I can create a `int msize = m.size()` so we only call it once. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/17544#discussion_r1475575700