RFR: 8336706: Optimize LocalDate.toString with StringBuilder.repeat

duke duke at openjdk.org
Fri Jul 19 23:26:31 UTC 2024


On Thu, 18 Jul 2024 05:21:36 GMT, Shaojin Wen <duke at openjdk.org> wrote:

> 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.

@wenshao 
Your change (at version af224217897a610d520c07f2805d91d6e41a9cba) is now ready to be sponsored by a Committer.

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

PR Comment: https://git.openjdk.org/jdk/pull/20229#issuecomment-2240626945


More information about the core-libs-dev mailing list