RFR: 8366224: Introduce DecimalDigits.appendPair for efficient two-digit formatting and refactor DateTimeHelper [v18]
Chen Liang
liach at openjdk.org
Thu Nov 13 04:20:06 UTC 2025
On Thu, 13 Nov 2025 04:07:45 GMT, Shaojin Wen <swen at openjdk.org> wrote:
>> This PR introduces a new efficient API for appending two-digit integers to StringBuilders and refactors DateTimeHelper to leverage this new functionality.
>>
>> Changes include:
>>
>> 1. New `appendPair` method for efficient two-digit integer formatting (00-99):
>> - Added `AbstractStringBuilder.appendLatin1(char c1, char c2)` with core implementation
>> - Added `JavaLangAccess.appendPair(StringBuilder, char c1, char c2)` for internal access
>> - Added `DecimalDigits.appendPair(StringBuilder, int)` public static utility method
>> - Enhanced Javadoc documentation for all new methods
>>
>> 2. Refactored `DateTimeHelper` to use the new `DecimalDigits.appendPair`:
>> - Updated `DateTimeHelper.formatTo` methods for `LocalDate` and `LocalTime`
>> - Replaced manual formatting logic with the new efficient two-digit appending
>> - Improved code clarity and consistency in date/time formatting
>>
>> These changes improve code clarity and performance when formatting two-digit numbers, particularly in date/time formatting scenarios.
>
> Shaojin Wen has updated the pull request incrementally with two additional commits since the last revision:
>
> - fix codestyle
> - digitQuad MergeStore & from @liach
test/jdk/jdk/internal/util/DecimalDigitsTest.java line 36:
> 34: * @summary Test DecimalDigits.appendPair method with LATIN1 and UTF16 encoding
> 35: * @modules java.base/jdk.internal.util
> 36: * @run testng test.jdk.internal.util.DecimalDigitsTest
We recommend using junit for new tests.
test/jdk/jdk/internal/util/DecimalDigitsTest.java line 41:
> 39:
> 40: @Test
> 41: public void testAppendPair() {
This duplicates testAppendPairWithLatin1Encoding and can be removed.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521325209
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521324512
More information about the core-libs-dev
mailing list