> 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..
Shaojin Wen has updated the pull request incrementally with one additional commit since the last revision: easier to compare ------------- Changes: - all: https://git.openjdk.org/jdk/pull/18177/files - new: https://git.openjdk.org/jdk/pull/18177/files/bb45da4d..30d4f9b0 Webrevs: - full: https://webrevs.openjdk.org/?repo=jdk&pr=18177&range=04 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=18177&range=03-04 Stats: 397 lines in 1 file changed: 198 ins; 199 del; 0 mod Patch: https://git.openjdk.org/jdk/pull/18177.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/18177/head:pull/18177 PR: https://git.openjdk.org/jdk/pull/18177