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

Shaojin Wen swen at openjdk.org
Wed Nov 12 08:32:42 UTC 2025


> 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 with a new target base due to a merge or a rebase. The pull request now contains 18 commits:

 - Merge remote-tracking branch 'upstream/master' into appendPair_202508
 - use append string
 - remove assert & newCapacity
 - fix assert
 - Merge remote-tracking branch 'upstream/master' into appendPair_202508
 - Fix JavaLangAccess.appendLatin1 javadoc to match method signature
   
   The previous javadoc incorrectly described the method as appending a two-digit
   integer representation, but the method actually appends two Latin-1 characters.
   Updated the documentation to accurately reflect the method's behavior.
   
   Co-authored-by: Qwen-Coder <qwen-coder at alibabacloud.com>
 - Merge remote-tracking branch 'upstream/master' into appendPair_202508
 - Merge remote-tracking branch 'upstream/master' into appendPair_202508
 - appendPair instead of appendLatin1(char, char)
 - Revert "appendPair instead of append(char, char)"
   
   This reverts commit d969a235e54da4ac96b7205982624f52305cae31.
 - ... and 8 more: https://git.openjdk.org/jdk/compare/76a0732b...4e77cc58

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

Changes: https://git.openjdk.org/jdk/pull/26911/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=26911&range=14
  Stats: 156 lines in 7 files changed: 125 ins; 4 del; 27 mod
  Patch: https://git.openjdk.org/jdk/pull/26911.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/26911/head:pull/26911

PR: https://git.openjdk.org/jdk/pull/26911


More information about the core-libs-dev mailing list