8337832: Optimize datetime toString

Reviewed-by: scolebourne, liach, naoto
This commit is contained in:
Shaojin Wen 2024-08-27 22:10:05 +00:00 committed by Chen Liang
parent b1b4cd429a
commit 449ca2c3c1
4 changed files with 31 additions and 9 deletions

View file

@ -1966,10 +1966,17 @@ public final class LocalDateTime
@Override
public String toString() {
var buf = new StringBuilder(29);
formatTo(buf);
return buf.toString();
}
/**
* Prints the toString result to the given buf, avoiding extra string allocations.
*/
void formatTo(StringBuilder buf) {
date.formatTo(buf);
buf.append('T');
time.formatTo(buf);
return buf.toString();
}
//-----------------------------------------------------------------------