File tree 4 files changed +31
-9
lines changed
src/java.base/share/classes/java/time
4 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -1966,10 +1966,17 @@ public int hashCode() {
1966
1966
@ Override
1967
1967
public String toString () {
1968
1968
var buf = new StringBuilder (29 );
1969
+ formatTo (buf );
1970
+ return buf .toString ();
1971
+ }
1972
+
1973
+ /**
1974
+ * Prints the toString result to the given buf, avoiding extra string allocations.
1975
+ */
1976
+ void formatTo (StringBuilder buf ) {
1969
1977
date .formatTo (buf );
1970
1978
buf .append ('T' );
1971
1979
time .formatTo (buf );
1972
- return buf .toString ();
1973
1980
}
1974
1981
1975
1982
//-----------------------------------------------------------------------
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2012, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -1923,7 +1923,10 @@ public int hashCode() {
1923
1923
*/
1924
1924
@ Override
1925
1925
public String toString () {
1926
- return dateTime .toString () + offset .toString ();
1926
+ var offsetStr = offset .toString ();
1927
+ var buf = new StringBuilder (29 + offsetStr .length ());
1928
+ dateTime .formatTo (buf );
1929
+ return buf .append (offsetStr ).toString ();
1927
1930
}
1928
1931
1929
1932
//-----------------------------------------------------------------------
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2012, 2023 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -1398,7 +1398,10 @@ public int hashCode() {
1398
1398
*/
1399
1399
@ Override
1400
1400
public String toString () {
1401
- return time .toString () + offset .toString ();
1401
+ var offsetStr = offset .toString ();
1402
+ var buf = new StringBuilder (18 + offsetStr .length ());
1403
+ time .formatTo (buf );
1404
+ return buf .append (offsetStr ).toString ();
1402
1405
}
1403
1406
1404
1407
//-----------------------------------------------------------------------
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2012, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2012, 2024 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -2214,11 +2214,20 @@ public int hashCode() {
2214
2214
*/
2215
2215
@ Override // override for Javadoc
2216
2216
public String toString () {
2217
- String str = dateTime .toString () + offset .toString ();
2217
+ var offsetStr = offset .toString ();
2218
+ var zoneStr = (String ) null ;
2219
+ int length = 29 + offsetStr .length ();
2218
2220
if (offset != zone ) {
2219
- str += '[' + zone .toString () + ']' ;
2221
+ zoneStr = zone .toString ();
2222
+ length += zoneStr .length () + 2 ;
2220
2223
}
2221
- return str ;
2224
+ var buf = new StringBuilder (length );
2225
+ dateTime .formatTo (buf );
2226
+ buf .append (offsetStr );
2227
+ if (zoneStr != null ) {
2228
+ buf .append ('[' ).append (zoneStr ).append (']' );
2229
+ }
2230
+ return buf .toString ();
2222
2231
}
2223
2232
2224
2233
//-----------------------------------------------------------------------
You can’t perform that action at this time.
0 commit comments