RFR: 8355177: Speed up StringBuilder::append(char[]) via Unsafe::copyMemory [v4]
Roger Riggs
rriggs at openjdk.org
Mon May 12 18:35:53 UTC 2025
On Fri, 2 May 2025 18:11:54 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> src/java.base/share/classes/java/lang/StringUTF16.java line 1322:
>>
>>> 1320: val,
>>> 1321: Unsafe.ARRAY_BYTE_BASE_OFFSET + ((long) index << 1),
>>> 1322: ((long) (end - off)) << 1);
>>
>> This use of Unsafe is not warranted. If it can't be done with arrayCopy, leave the original code as is.
>
>> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24773#discussion_r2085236701
More information about the core-libs-dev
mailing list