On Sun, 10 Mar 2024 16:11:12 GMT, Shaojin Wen <d...@openjdk.org> wrote:
> The current BigDecimal(String) constructor calls String#toCharArray, which > has a memory allocation. > > > public BigDecimal(String val) { > this(val.toCharArray(), 0, val.length()); // allocate char[] > } > > > When the length is greater than 18, create a char[] > > > boolean isCompact = (len <= MAX_COMPACT_DIGITS); // 18 > if (!isCompact) { > // ... > } else { > char[] coeff = new char[len]; // allocate char[] > // ... > } > > > This PR eliminates the two memory allocations mentioned above, resulting in > an approximate 60% increase in performance.. src/java.base/share/classes/java/math/BigDecimal.java line 1049: > 1047: if (dot) > 1048: ++scl; > 1049: } else if ((c == 'e') || (c == 'E')) { Can we keep this block in parity with the `char[]` version? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18177#discussion_r1519691857