class LocalDate { public String toString() { if (absYear < 1000) { if (yearValue < 0) { buf.append(yearValue - 10000).deleteCharAt(1); } else { buf.append(yearValue + 10000).deleteCharAt(0); } // ... } }
Currently, LocalDate.toString causes an extra memory copy when processing years < 1000. This can be replaced by using StringBuilder.repeat, which is more concise and has better performance. ------------- Commit messages: - use StringBuilder#repeat append zeros Changes: https://git.openjdk.org/jdk/pull/20229/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=20229&range=00 Issue: https://bugs.openjdk.org/browse/JDK-8336706 Stats: 6 lines in 1 file changed: 2 ins; 2 del; 2 mod Patch: https://git.openjdk.org/jdk/pull/20229.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/20229/head:pull/20229 PR: https://git.openjdk.org/jdk/pull/20229