RFR: 8337832: Optimize datetime toString

Chen Liang liach at openjdk.org
Mon Aug 5 18:09:05 UTC 2024


On Sat, 27 Jul 2024 13:45:11 GMT, Shaojin Wen <duke at openjdk.org> wrote:

> Similar to PR #20321, this improves performance by providing a method that passes in a StringBuilder to avoid unnecessary object allocation.

src/java.base/share/classes/java/time/ZonedDateTime.java line 2222:

> 2220:         if (offset != zone) {
> 2221:             zoneStr = zone.toString();
> 2222:             length += zoneStr.length();

Suggestion:

            length += zoneStr.length() + 2;

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20368#discussion_r1693963178


More information about the core-libs-dev mailing list