On Sun, 26 Feb 2023 17:28:08 GMT, Tagir F. Valeev <tval...@openjdk.org> wrote:
>> Jim Laskey has updated the pull request incrementally with one additional >> commit since the last revision: >> >> PR Cleanup > > src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1903: > >> 1901: int total = count * length; >> 1902: int limit = offset + total; >> 1903: ensureCapacityInternal(limit); > > If I understand correctly, this may cause double reallocation, if inflation > is necessary (string to spend is utf16 while current coder is latin1). Can > this be optimized, at least for String/ASB inputs? Sorry if I'm missing > something. Inflation of a buffer can only happen once. Adding the first copy (append) causing expansion (reallocatio ) and then expanding again to handle the remaining copies is something that happens frequently. Better to expand once for all cases and take the one time hit for transition from Latin1 to UTF16. Make sense? ------------- PR: https://git.openjdk.org/jdk/pull/12728