8336706: Optimize LocalDate.toString with StringBuilder.repeat
Reviewed-by: liach, rriggs
This commit is contained in:
parent
e3acf4c627
commit
491b9f5efc
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* 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);
|
StringBuilder buf = new StringBuilder(10);
|
||||||
if (absYear < 1000) {
|
if (absYear < 1000) {
|
||||||
if (yearValue < 0) {
|
if (yearValue < 0) {
|
||||||
buf.append(yearValue - 10000).deleteCharAt(1);
|
buf.append('-');
|
||||||
} else {
|
|
||||||
buf.append(yearValue + 10000).deleteCharAt(0);
|
|
||||||
}
|
}
|
||||||
|
buf.repeat('0', absYear < 10 ? 3 : absYear < 100 ? 2 : 1);
|
||||||
|
buf.append(absYear);
|
||||||
} else {
|
} else {
|
||||||
if (yearValue > 9999) {
|
if (yearValue > 9999) {
|
||||||
buf.append('+');
|
buf.append('+');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user