8300818: Reduce complexity of padding with DateTimeFormatter

Reviewed-by: redestad, rriggs
This commit is contained in:
Sergey Tsypanov 2023-05-01 18:24:07 +00:00 committed by Roger Riggs
parent ae5f678fba
commit 561ec9c5a0
2 changed files with 85 additions and 2 deletions

View file

@ -2612,9 +2612,15 @@ public final class DateTimeFormatterBuilder {
throw new DateTimeException(
"Cannot print as output of " + len + " characters exceeds pad width of " + padWidth);
}
for (int i = 0; i < padWidth - len; i++) {
buf.insert(preLen, padChar);
var count = padWidth - len;
if (count == 0) {
return true;
}
if (count == 1) {
buf.insert(preLen, padChar);
return true;
}
buf.insert(preLen, String.valueOf(padChar).repeat(count));
return true;
}