On Fri, 14 Nov 2025 15:48:16 GMT, Shaojin Wen <[email protected]> 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:
> 
>   add test and from @RogerRiggs

The `DecimalDigits.appendPair` and `appendQuad` methods will experience 
performance degradation if a `StringBuilder` with `Encoding UTF16` is passed to 
them. This occurs when `DecimalDigits.appendPair` or `appendQuad` is used in 
`DateTimeFormatter::formatTo`.

For example:

LocalDateTime localDateTime = ...;
StringBuilder sb = new StringBuilder();
sb.append('€');
DateTimeFormatter.ISO_DATE_TIME.formatTo(localDateTime, sb);

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

PR Comment: https://git.openjdk.org/jdk/pull/26911#issuecomment-3533393414

Reply via email to