RFR: 8327791: Optimization for new BigDecimal(String) [v12]
Shaojin Wen
duke at openjdk.org
Wed Mar 13 13:15:18 UTC 2024
On Wed, 13 Mar 2024 13:11:48 GMT, Shaojin Wen <duke at openjdk.org> wrote:
>> src/java.base/share/classes/java/math/BigDecimal.java line 596:
>>
>>> 594: // First compact case, we need not to preserve the character
>>> 595: // and we can just compute the value in place.
>>> 596: for (; ; c = val.charAt(++offset)) {
>>
>> This looks gnarly, and it's unclear if it's correct for invalid inputs like `""`, `"-"` and `"+"` since you're not testing for `len > 0` before going into the loop. Can you make sure there are tests covering such inputs and try to simplify this?
>
> If the input is "+" or "-" an exception will be thrown on line 583
>
> boolean isneg = c == '-'; // leading minus means negative
> if (isneg || c == '+') {
> c = val.charAt(++offset);
> len--;
> }
if the input is "" an exception will be throw on line 579
int offset = 0;
char c = val.charAt(offset);
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18177#discussion_r1523237018
More information about the core-libs-dev
mailing list