On Mon, 30 Aug 2021 13:54:13 GMT, Claes Redestad <redes...@openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1730: >> >>> 1728: } >>> 1729: >>> 1730: private void putStringAt(int index, String str) { >> >> Can we replace all the calls to this method with calls to previous method as >> `putStringAt(index, str, 0, str.length())` taking into account that in all >> usecases `str.length()` is already calculated into a local var? > > No, I don't think so. The only use of this I can find is at line 1298 which > effectively adds a substring: `putStringAt(dstOffset, (String) s, start, > end);` What about lines 582, 1003 and 1175? E.g. 582 public AbstractStringBuilder append(String str) { if (str == null) { return appendNull(); } int len = str.length(); ensureCapacityInternal(count + len); putStringAt(count, str); // couldn't it be putStringAt(count, str, 0, len); count += len; return this; } Doing this here and in other places allows to rid `private void putStringAt(int index, String str)` completely and reduce one nested method call, right? ------------- PR: https://git.openjdk.java.net/jdk/pull/5291