On Thu, 11 Jan 2024 19:21:00 GMT, Joshua Cao <d...@openjdk.org> wrote:

>>> We don't need to compute max() here. 
>>> [tryPresize()](https://github.com/openjdk/jdk/blob/8a4dc79e1a40e7115e2971af81623b6b0368f41c/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java#L2397)
>>>  does that already.
>> 
>> The code you reference is only executed if `table == null` but in this case 
>> we know it is not `null` because we only call `tryPresize()` if `table != 
>> null`.
>> 
>> In general, it's hard fro me to understand what `tryPresize(int size)` is 
>> doing and if its `size` argument is supposed to contain the additional 
>> number of elements which will be inserted into the hash map or if it is a 
>> hint for the new total size of the hash map. Can you explain?
>
>> tryPresize(int size) is doing and if its size argument is supposed to 
>> contain the additional number of elements which will be inserted into the 
>> hash map or if it is a hint for the new total size of the hash map
> 
> Argument `size` for `tryPresize()` is a hint for the **new total size** of 
> the hash map. If the size is too small compared to the current size of the 
> map, there will be no resizing.

Thanks. In that case, calling `tryPresize()` with `size < this.size()` doesn't 
make sense and we should call it with `this.size() + m.size()`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/17116#discussion_r1450063503

Reply via email to