RFR (XS) 8076759: AbstractStringBuilder.append(...) should ensure enough capacity for the upcoming "trivial" append calls

Ulf Zibis Ulf.Zibis at CoSoCo.de
Fri May 8 12:46:13 UTC 2015

Am 08.05.2015 um 13:28 schrieb Aleksey Shipilev:
> On 05/07/2015 06:00 PM, Ulf Zibis wrote:
>> May be:
>> ..., then a new internal array becomes allocated and refilled with
>> greater capacity.
>> ... to give a hint, that this action may be expensive.
> The Javadoc already says "If the current capacity is less than the
> argument, then a new internal array is allocated with greater capacity",
> which seems to be what you are saying.

Allocating a new array is one thing, but copying the old data into the new one is another story 
where the cost is dependent on it's size. Also theoretically, AbstractStringBuilder could hold 
multiple arrays to avoid the copying and solve memory fragmentation issues. Both aspects are 
implementation details, so when mentioned in Javadoc, my thought is, to do that in completeness. 
Maybe there is a better wording than "refill" to indicate the internal copying.


More information about the core-libs-dev mailing list