RFR: 8366224: Introduce DecimalDigits.appendPair for efficient two-digit formatting and refactor DateTimeHelper [v25]

Roger Riggs rriggs at openjdk.org
Thu Nov 20 15:41:16 UTC 2025


On Sat, 15 Nov 2025 14:45:48 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 one additional commit since the last revision:
> 
>   remove DecimalDigitsTest

Looks good; a few suggestions on comments in DecimalDigits.

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

> 480:      * values from 10 to 99 become three leading zeros (e.g., 25 becomes "0025"),
> 481:      * values from 100 to 999 become two leading zeros (e.g., 123 becomes "0123"),
> 482:      * and values from 1000 to 9999 become one leading zero or no leading zeros.

Minor correction to comment:
Suggestion:

     * values from 10 to 99 add two leading zeros (e.g., 25 becomes "0025"),
     * values from 100 to 999 add one leading zero (e.g., 123 becomes "0123"),
     * and values from 1000 to 9999 have no leading zeros.

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

Marked as reviewed by rriggs (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/26911#pullrequestreview-3488402521
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2546472219


More information about the core-libs-dev mailing list