On Wed, 4 Jun 2025 18:18:39 GMT, Johannes Graham <[email protected]> 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 192:
> 190: long v = Long.parseUnsignedLong(new String(digits, 0, count));
> 191: if (v < 0) {
> 192: if (Long.compareUnsigned(v, Long.MIN_VALUE) == 0) {
Unsigned == should be equivalent to signed ==, so `v == Long.MIN_VALUE` should
be sufficient.
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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25644#discussion_r2127580172
PR Review Comment: https://git.openjdk.org/jdk/pull/25644#discussion_r2127581325