Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream
Martin Buchholz
martinrb at google.com
Thu Mar 11 00:48:10 UTC 2010
On Wed, Mar 10, 2010 at 09:36, Ulf Zibis <Ulf.Zibis at gmx.de> wrote:
> Am 10.03.2010 00:22, schrieb Martin Buchholz:
>>
>> On Tue, Mar 9, 2010 at 15:11, Ulf Zibis<Ulf.Zibis at gmx.de> wrote:
>>
>>
>>>
>>> Can you explain the mystery about "+ 2" ?
>>>
>>
>> It's exactly the same as the old resizing behavior.
>
> In detail I meant, if you have any idea, why the original designers could
> have chosen the "+1".
> The code would be smarter, if ommited, + would serve the algorithm-loved
> arrays of [base-2-] "round" sizes.
I bet what happened is that the +2 is necessary for an initial capacity of 0.
It turns out that the current implementation disallows this,
so it it possible to simply double the size, but I am not going to
change it now.
On the other hand, you could consider it a feature
that very small arrays should grow more rapidly than a factor of two.
Martin
More information about the core-libs-dev
mailing list