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

Jim Laskey jlaskey at openjdk.org
Thu Feb 23 16:37:02 UTC 2023


On Thu, 23 Feb 2023 15:56:37 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>> Add the ability to repeatedly append char and CharSequence data to StringBuilder/StringBuffer.
>
> src/java.base/share/classes/java/lang/AbstractStringBuilder.java line 1876:
> 
>> 1874:         int length = this.count - offset;
>> 1875:         int valueLength = length << coder;
>> 1876:         if ((Integer.MAX_VALUE - offset) / count < valueLength) {
> 
> Can this check be done with multiply instead of divide?

This was a recommended pattern when I was working on String. It handles arithmetic overflow. Divide magic there would be confusing.

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

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


More information about the core-libs-dev mailing list