On Wed, 14 May 2025 13:47:11 GMT, Johannes Graham <d...@openjdk.org> wrote:

>> Optimize `BigDecimal.valueOf(double)` by using `FormattedFPDecimal` instead 
>> of converting to decimal string and then parsing it. This results in an 
>> approximate 6x improvement for me.
>
> Johannes Graham has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   address review suggestions

src/java.base/share/classes/jdk/internal/math/FormattedFPDecimal.java line 94:

> 92:         final int targetPrec =
> 93:                 // No extra trailing digit needed
> 94:                 (-3 <= expR && expR <= -1) ? 1

Suggestion:

                (-3 <= expR && expR < 0) ? 1

Fully equivalent, but matches the `Double.toString(double)` spec more closely.

src/java.base/share/classes/jdk/internal/math/FormattedFPDecimal.java line 97:

> 95: 
> 96:                 // Keep digits to left of decimal, plus leave a trailing 
> zero
> 97:                 : (0 <= expR && expR <= 6) ? expR + 2 :

Suggestion:

                : (0 <= expR && expR < 7) ? expR + 2 :

Fully equivalent, but matches the `Double.toString(double)` spec more closely.

src/java.base/share/classes/jdk/internal/math/FormattedFPDecimal.java line 109:

> 107:         if (prec < targetPrec) {
> 108:             // Add zeros needed to reach target precision
> 109:             int addZeros = targetPrec - prec;

Suggestion:

            final int addZeros = targetPrec - prec;

Just to be consistent with the usage of `final` in this method.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2089090546
PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2089090644
PR Review Comment: https://git.openjdk.org/jdk/pull/25173#discussion_r2089092505

Reply via email to