8336706: Optimize LocalDate.toString with StringBuilder.repeat

Reviewed-by: liach, rriggs
This commit is contained in:
Shaojin Wen 2024-07-20 06:54:19 +00:00 committed by Chen Liang
parent e3acf4c627
commit 491b9f5efc

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -2154,10 +2154,10 @@ public final class LocalDate
StringBuilder buf = new StringBuilder(10);
if (absYear < 1000) {
if (yearValue < 0) {
buf.append(yearValue - 10000).deleteCharAt(1);
} else {
buf.append(yearValue + 10000).deleteCharAt(0);
buf.append('-');
}
buf.repeat('0', absYear < 10 ? 3 : absYear < 100 ? 2 : 1);
buf.append(absYear);
} else {
if (yearValue > 9999) {
buf.append('+');