On Tue, 6 May 2025 08:22:51 GMT, Shaojin Wen <s...@openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/StringConcatHelper.java line 435:
>> 
>>> 433:     static String doConcat(String s1, String s2) {
>>> 434:         byte coder = (byte) (s1.coder() | s2.coder());
>>> 435:         int newLength = checkOverflow(s1.length() + s2.length()) << 
>>> coder;
>> 
>> Might be mildly inefficient for this case since `checkOverflow` is designed 
>> for the compound length+coder `long`. Since this is only used in the simple 
>> path it should be easy for JITs to optimize, though.
>
> @ForceInline
>     static int checkOverflow(int value) {
>         if (value >= 0) {
>             return value;
>         }
>         throw new OutOfMemoryError("Overflow: String length out of range");
>     }
> 
>     private static long checkOverflow(long lengthCoder) {
>         if ((int)lengthCoder >= 0) {
>             return lengthCoder;
>         }
>         throw new OutOfMemoryError("Overflow: String length out of range");
>     }
> 
> @cl4es There are two checkOverflow methods

Exactly. The one used here is the (int) variant.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25038#discussion_r2075011584

Reply via email to