On Wed, 1 Nov 2023 17:40:04 GMT, Raffaello Giulietti <rgiulie...@openjdk.org> 
wrote:

> Prevent a `NegativeArraySizeException` in `BigDecimal.toPlainString()`, 
> throwing `OutOfMemoryError` instead to indicate that the resulting `String` 
> would be too large.

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

> 3516:             for (int i = 0; i < trailingZeros; i++) {
> 3517:                 buf.append('0');
> 3518:             }

A bit more compact as:
Suggestion:

            StringBuilder buf = new StringBuilder(len);
            buf.append(str);
            buf.repeat('0', trailingZeros);

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

> 3549:             for (int i = insertionPoint; i < 0; ++i) {
> 3550:                 buf.append('0');
> 3551:             }

Would this be the same as: 
`buf.repeat('0',  -i);`

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16457#discussion_r1385363742
PR Review Comment: https://git.openjdk.org/jdk/pull/16457#discussion_r1385372642

Reply via email to