RFR: 8366224: Introduce DecimalDigits.appendPair for efficient two-digit formatting and refactor DateTimeHelper [v17]
Shaojin Wen
swen at openjdk.org
Thu Nov 13 04:07:46 UTC 2025
On Thu, 13 Nov 2025 00:22:09 GMT, Chen Liang <liach at openjdk.org> wrote:
>> Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision:
>>
>> static field JLA
>
> src/java.base/share/classes/java/time/MonthDay.java line 753:
>
>> 751: @Override
>> 752: public String toString() {
>> 753: StringBuilder buf = new StringBuilder(10);
>
> Why is this set to 10 instead of 7?
I suggest not making this change, as it is irrelevant to this PR.
> src/java.base/share/classes/java/time/YearMonth.java line 1201:
>
>> 1199: public String toString() {
>> 1200: int absYear = Math.abs(year);
>> 1201: StringBuilder buf = new StringBuilder(9);
>
> I think 7 is better for most cases, right?
I suggest not making this change, as it is irrelevant to this PR.
> src/java.base/share/classes/java/time/ZoneOffset.java line 466:
>
>> 464: } else {
>> 465: int absTotalSeconds = Math.abs(totalSeconds);
>> 466: StringBuilder buf = new StringBuilder();
>
> This can be pre-sized to 9 (or 7 if seconds is 0)
I suggest not making this change, as it is irrelevant to this PR.
> src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 463:
>
>> 461: */
>> 462: public static void appendPair(StringBuilder buf, int v) {
>> 463: int packed = DIGITS[v & 0x7f];
>
> We should assert v is in range so errors can be caught when we run tests. Same for appendQuad.
To maintain consistency with other putPair methods in DecimalDigits, trust the caller and do not perform assert checks, as assert checks can increase codeSize and potentially impact performance.
> src/java.base/share/classes/jdk/internal/util/DecimalDigits.java line 484:
>
>> 482: */
>> 483: public static void appendQuad(StringBuilder buf, int v) {
>> 484: int y01 = v / 100;
>
> Same assert bound check request
To maintain consistency with other putPair methods in DecimalDigits, trust the caller and do not perform assert checks, as assert checks can increase codeSize and potentially impact performance.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521259148
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521259449
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521259773
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521265811
PR Review Comment: https://git.openjdk.org/jdk/pull/26911#discussion_r2521266282
More information about the core-libs-dev
mailing list