On Fri, 19 Dec 2025 06:10:56 GMT, Shaojin Wen <[email protected]> wrote:

>> Continue to complete PR #16006 and PR #21593 to improve BigDecimal::toString 
>> and BigDecimal::toPlainString performance and reduce duplicate code
>
> Shaojin Wen has updated the pull request with a new target base due to a 
> merge or a rebase. The pull request now contains 37 commits:
> 
>  - Merge remote-tracking branch 'upstream/master' into dec_to_str_202501
>  - simplify layoutChars
>  - comments, from @liach
>  - getValueString -> getCompactValueString, from @liach
>  - Refactor BigDecimal string creation to use 
> JLA.uncheckedNewStringWithLatin1Bytes
>    
>    Co-authored-by: Qwen-Coder <[email protected]>
>  - Merge remote-tracking branch 'upstream/master' into dec_to_str_202501
>    
>    # Conflicts:
>    #  src/java.base/share/classes/java/math/BigDecimal.java
>  - Merge remote-tracking branch 'upstream/master' into dec_to_str_202501
>    
>    # Conflicts:
>    #  src/java.base/share/classes/java/math/BigDecimal.java
>    #  src/java.base/share/classes/jdk/internal/util/DecimalDigits.java
>    #  test/micro/org/openjdk/bench/java/math/BigDecimals.java
>  - Merge remote-tracking branch 'upstream/master' into dec_to_str_202501
>  - Merge remote-tracking branch 'upstream/master' into dec_to_str_202501
>    
>    # Conflicts:
>    #  src/java.base/share/classes/jdk/internal/util/DecimalDigits.java
>  - remove getChars(long, int, char[])
>  - ... and 27 more: https://git.openjdk.org/jdk/compare/3f33eaa4...32d95b36

src/java.base/share/classes/java/math/BigDecimal.java line 3456:

> 3454: 
> 3455:         long intCompact = this.intCompact;
> 3456:         // currency fast path

This comment should be moved to the `scale2` method.

src/java.base/share/classes/java/math/BigDecimal.java line 3468:

> 3466:     }
> 3467: 
> 3468:     private static String getValueString(int signum, long 
> intCompactAbs, int intCompactAbsSize, int scale) {

I recommend naming this `getCompactValueString` to indicate this differs from 
`getValueString` by accepting only compact values. Something like:

"Returns a digit.digit string for a compact value"

src/java.base/share/classes/java/math/BigDecimal.java line 4223:

> 4221:         if ((scale >= 0) && (adjusted >= -6)) { // plain number
> 4222:             return getValueString(signum, coeff, scale);
> 4223:         }

Let's move this `if ((scale >= 0) && (adjusted >= -6)) {` into the `else` for 
`if (intCompact != INFLATED) {` above for parity.

src/java.base/share/classes/java/math/BigDecimal.java line 4237:

> 4235:             if (coeffLen > 1) {          // more to come
> 4236:                 buf.append('.')
> 4237:                    .append(coeff, 1, coeffLen);

Is this right that the old end is `coeffLen - 1` but the new end is `coeffLen`? 
I don't see why there should be no more `-1`.

src/java.base/share/classes/java/math/BigDecimal.java line 4289:

> 4287:         return JLA.uncheckedNewStringWithLatin1Bytes(buf);
> 4288:     }
> 4289:     private String unscaledString() {

Suggestion:

    }

    private String unscaledString() {

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

PR Review Comment: https://git.openjdk.org/jdk/pull/23310#discussion_r2621031566
PR Review Comment: https://git.openjdk.org/jdk/pull/23310#discussion_r2621027174
PR Review Comment: https://git.openjdk.org/jdk/pull/23310#discussion_r2621172443
PR Review Comment: https://git.openjdk.org/jdk/pull/23310#discussion_r2621180081
PR Review Comment: https://git.openjdk.org/jdk/pull/23310#discussion_r2621181708

Reply via email to