RFR: JDK-8302323 Add repeat methods to StringBuilder/StringBuffer [v2]

Tagir F. Valeev tvaleev at openjdk.org
Sun Feb 26 17:32:06 UTC 2023


On Thu, 23 Feb 2023 17:39:10 GMT, Jim Laskey <jlaskey at openjdk.org> wrote:

>> Add the ability to repeatedly append char and CharSequence data to StringBuilder/StringBuffer.
>
> 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 1893:

> 1891:         }
> 1892:         int length = cs.length();
> 1893:         if (length == 1) {

It looks like, handling length == 0 case would be reasonable.

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.

-------------

PR: https://git.openjdk.org/jdk/pull/12728


More information about the core-libs-dev mailing list