RFR: 8349176: Speed up Integer/Long.toString via StringConcatHelper::newArray [v4]

Shaojin Wen swen at openjdk.org
Sat May 3 18:33:48 UTC 2025


On Sat, 3 May 2025 05:03:36 GMT, Shaojin Wen <swen at openjdk.org> wrote:

>> The byte[] allocated in Integer/Long.toString is fully filled, so we can use StringConcatHelper::newArray to create byte[] to improve performance.
>
> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
> 
>   use Unsafe::allocateUninitializedArray

public static String toString(int i) {
        int size = DecimalDigits.stringSize(i);
        byte coder = COMPACT_STRINGS ? LATIN1 : UTF16;
        byte[] buf = (byte[]) Unsafe.getUnsafe().allocateUninitializedArray(byte.class, size << coder);
        if (coder == LATIN1) {
            DecimalDigits.getCharsLatin1(i, size, buf);
        } else {
            DecimalDigits.getCharsUTF16(i, size, buf);
        }
        return new String(buf, coder);
    }

This implementation has a smaller code size and the same performance, but it changes the code structure, so I did not use it.

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

PR Comment: https://git.openjdk.org/jdk/pull/23353#issuecomment-2848749465


More information about the core-libs-dev mailing list