RFR: 8355177: Speed up StringBuilder::append(char[]) via Unsafe::copyMemory [v4]

Shaojin Wen swen at openjdk.org
Mon May 12 22:50:52 UTC 2025


On Mon, 12 May 2025 18:33:03 GMT, Roger Riggs <rriggs at openjdk.org> wrote:

>>> This use of Unsafe is not warranted. If it can't be done with arrayCopy, leave the original code as is.
>> 
>> The core library also uses Unsafe.copyMemory in many places. Can it be used in this scenario? Or can we find other ways to copy char[] to byte[]?
>
> You may have overlooked the behavior of putChar to swap the order of the bytes depending on whether its big or little endian.

There is no endianness issue here. The byte[] of StringUTF16 has the same endianness order in memory as char[].

The Unsafe::CopyMemory operation here is the same as the Unsafe::putChar and StringUTF16::putChar operation on StringUTF16 byte[], so there is no endianness issue.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2085638167


More information about the core-libs-dev mailing list