<i18n dev> RFR: 8358880: Performance of parsing with DecimalFormat can be improved
Johannes Graham
duke at openjdk.org
Mon Jun 9 17:16:03 UTC 2025
On Wed, 4 Jun 2025 23:15:37 GMT, Chen Liang <liach at openjdk.org> wrote:
>> This PR replaces construction of intermediate strings to be parsed with more direct manipulation of numbers. It also has a more streamlined mechanism of handling `Long.MIN_VALUE` when parsing longs by using `Long.parseUnsignedLong`
>>
>> As a small side-effect it also eliminates the use of a cached StringBuilder in DigitList.
>>
>> Testing:
>> - GHA
>> - Local run of tier 2 and jtreg:jdk/java/text
>> - New benchmark: DecimalFormatParseBench
>
> src/java.base/share/classes/java/text/DigitList.java line 198:
>
>> 196: }
>> 197: long pow10 = Math.powExact(10L, Math.max(0, decimalAt - count));
>> 198: return Math.multiplyExact(v, pow10);
>
> These two methods throw ArithmeticException. This needs to be rethrown as NumberFormatException.
This one is a little odd. The parse methods that call `getLong` are not supposed to throw `NumberFormatException` either. So wherever `getLong` is called, it must be preceded by a check to `fitsIntoLong`, which should avoid any exceptions here. That said, rethrowing as NFE would avoid new surprises. What do you think?
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25644#discussion_r2127637333
More information about the i18n-dev
mailing list