mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8337832: Optimize datetime toString
Reviewed-by: scolebourne, liach, naoto
This commit is contained in:
parent
b1b4cd429a
commit
449ca2c3c1
4 changed files with 31 additions and 9 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012, 2021, 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
|
||||
|
@ -2214,11 +2214,20 @@ public final class ZonedDateTime
|
|||
*/
|
||||
@Override // override for Javadoc
|
||||
public String toString() {
|
||||
String str = dateTime.toString() + offset.toString();
|
||||
var offsetStr = offset.toString();
|
||||
var zoneStr = (String) null;
|
||||
int length = 29 + offsetStr.length();
|
||||
if (offset != zone) {
|
||||
str += '[' + zone.toString() + ']';
|
||||
zoneStr = zone.toString();
|
||||
length += zoneStr.length() + 2;
|
||||
}
|
||||
return str;
|
||||
var buf = new StringBuilder(length);
|
||||
dateTime.formatTo(buf);
|
||||
buf.append(offsetStr);
|
||||
if (zoneStr != null) {
|
||||
buf.append('[').append(zoneStr).append(']');
|
||||
}
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue