RFR: JDK-8302323 Add repeat methods to StringBuilder/StringBuffer [v3]
Tagir F. Valeev
tvaleev at openjdk.org
Tue Feb 28 07:48:09 UTC 2023
On Mon, 27 Feb 2023 13:30:47 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:
>
> Optimize for empty CharSequence
src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1903:
> 1901: throw new OutOfMemoryError("Required length exceeds implementation limit");
> 1902: }
> 1903: int total = count * length;
We may avoid division if we use the long type:
long totalLong = ((long) count) * length;
if (totalLong > Integer.MAX_VALUE - offset) {
throw new OutOfMemoryError("Required length exceeds implementation limit");
}
int total = (int) totalLong;
Should be faster.
-------------
PR: https://git.openjdk.org/jdk/pull/12728
More information about the core-libs-dev
mailing list