RFR: [6904367]: (coll) IdentityHashMap is resized before exceeding the expected maximum size

Peter Levart peter.levart at gmail.com
Tue Jul 8 15:08:03 UTC 2014


On 07/08/2014 03:56 PM, Martin Buchholz wrote:
> On Tue, Jul 8, 2014 at 5:30 AM, Peter Levart <peter.levart at gmail.com> wrote:
>
>> On 07/08/2014 02:20 PM, Peter Levart wrote:
>>
>>> That's right. Not in put(). But in putAll() it can overflow, since the
>>> argument Map can be of any size that fits in int...
>>
> I took another look at putAll.  I think we can do more simply, relying on
> the checks in capacity and resize:
>
>            int n = m.size();
>           if (n == 0)
>               return;
> -        if (n > threshold) // conservatively pre-expand
> -            resize(capacity(n));
> +        if (n > size)
> +            resize(capacity(n)); // conservatively pre-expand
>
>           for (Entry<? extends K, ? extends V> e : m.entrySet())
>               put(e.getKey(), e.getValue());
>
> Also, note I'm trying to avoid (relatively expensive) integer division,
> except at compile time.
>
Nice.

Peter




More information about the core-libs-dev mailing list