Hello everyone,
I'd like to introduce a set of changes focused on optimizing the formatting of 
two-digit numbers within date and time formatting.
These changes introduce a new internal API, DecimalDigits.appendPair, designed 
for efficiently appending integers in the range 00-99 to a StringBuilder. This 
API is exposed for internal use via JavaLangAccess and is leveraged in 
DateTimeHelper to refactor the formatting logic for date and time components 
(month, day, hour, minute, second), aiming to improve both code clarity and 
performance.
The specific changes are as follows:
 1. Introduce `appendPair` method:
 * Added the core implementation appendPair(int i) to AbstractStringBuilder.
 * Provided internal access bridges via JavaLangAccess and 
System.JavaLangAccessImpl.
 * Added a public static utility method appendPair(StringBuilder, int) in 
DecimalDigits.
 2. Refactor `DateTimeHelper` to use `appendPair`:
 * Updated DateTimeHelper.formatTo methods for LocalDate and LocalTime to 
utilize the new DecimalDigits.appendPair for formatting month, day, hour, 
minute, and second components.
 3. Optimize year formatting:
 * Slightly refactored the year formatting logic to use subtraction instead of 
the modulo operation for calculating the lower two digits, which can offer a 
minor performance gain. A comment was added to clarify the safety of the input 
range for DecimalDigits.appendPair.
A draft PR containing these changes is now available at: 
https://github.com/openjdk/jdk/pull/26911 
<https://github.com/openjdk/jdk/pull/26911 >
Your review and feedback would be greatly appreciated.
Thank you!
-
Shaojin Wen

Reply via email to