RFR: 8342650: Move getChars to DecimalDigits

David Holmes dholmes at openjdk.org
Tue Nov 12 01:51:15 UTC 2024


On Tue, 12 Nov 2024 01:25:16 GMT, Shaojin Wen <swen at openjdk.org> wrote:

> This PR is a resubmission after PR #21593 was rolled back, and the unsafe offset overflow issue has been fixed.
> 
> Move getChars methods of StringLatin1 and StringUTF16 to DecimalDigits to reduce duplication
> 
> HexDigits and OctalDigits also include getCharsLatin1 and getCharsUTF16
> 
> Putting these two methods into DecimalDigits can avoid the need to expose them in JavaLangAccess
> Eliminate duplicate code in BigDecimal
> 
> 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.

@wenshao you need a new JBS issue to complete this work under.

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

PR Comment: https://git.openjdk.org/jdk/pull/22023#issuecomment-2469426151


More information about the core-libs-dev mailing list