On Fri, 17 Jan 2025 00:09:11 GMT, Shaojin Wen <s...@openjdk.org> wrote:

>> This PR is a resubmission after PR #21593 was rolled back, and the unsafe 
>> offset overflow issue has been fixed.
>> 
>> 1) Move getChars methods of StringLatin1 and StringUTF16 to DecimalDigits to 
>> reduce duplication.
>> 
>> 2) HexDigits and OctalDigits also include getCharsLatin1 and getCharsUTF16
>> 
>> 3) Putting these two methods into DecimalDigits can avoid the need to expose 
>> them in JavaLangAccess
>> Eliminate duplicate code in BigDecimal
>> 
>> 4) This PR will improve the performance of Integer/Long.toString and 
>> StringBuilder.append(int/long) scenarios. This is because Unsafe.putByte is 
>> used to eliminate array bounds checks, and of course this elimination is 
>> safe. In previous versions, in Integer/Long.toString and 
>> StringBuilder.append(int/long) scenarios, -COMPACT_STRING performed better 
>> than +COMPACT_STRING. This is because StringUTF16.getChars uses 
>> StringUTF16.putChar, which is similar to Unsafe.putChar, and there is no 
>> bounds check.
>
> Shaojin Wen has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   fix comment, from @rgiulietti

src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 434:

> 432: 
> 433:     private static void putCharUTF16(byte[] buf, int charPos, int c) {
> 434:         UNSAFE.putChar(buf, ARRAY_BYTE_BASE_OFFSET + ((long) charPos << 
> 1), (char) c);

I'm not sure we can put a `char` into a `byte[]`.
@cl4es is this safe on all platforms?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/22023#discussion_r1920383426

Reply via email to