On Mon, 27 Feb 2023 13:30:47 GMT, Jim Laskey <jlas...@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