Integrated: 8336706: Optimize LocalDate.toString with StringBuilder.repeat
Shaojin Wen
duke at openjdk.org
Sat Jul 20 06:56:35 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.
This pull request has now been integrated.
Changeset: 491b9f5e
Author: Shaojin Wen <shaojin.wensj at alibaba-inc.com>
Committer: Chen Liang <liach at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/491b9f5efc01fa36fb3c174e130b46bc69c8d707
Stats: 6 lines in 1 file changed: 2 ins; 2 del; 2 mod
8336706: Optimize LocalDate.toString with StringBuilder.repeat
Reviewed-by: liach, rriggs
-------------
PR: https://git.openjdk.org/jdk/pull/20229
More information about the core-libs-dev
mailing list