mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8325730: StringBuilder.toString allocation for the empty String
Reviewed-by: jlaskey, shade
This commit is contained in:
parent
aa792eabab
commit
d2590c69b4
4 changed files with 25 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1994, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1994, 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
|
||||
|
@ -735,6 +735,9 @@ import jdk.internal.vm.annotation.IntrinsicCandidate;
|
|||
@Override
|
||||
@IntrinsicCandidate
|
||||
public synchronized String toString() {
|
||||
if (length() == 0) {
|
||||
return "";
|
||||
}
|
||||
if (toStringCache == null) {
|
||||
return toStringCache = new String(this, null);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 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
|
||||
|
@ -471,8 +471,11 @@ public final class StringBuilder
|
|||
@Override
|
||||
@IntrinsicCandidate
|
||||
public String toString() {
|
||||
if (length() == 0) {
|
||||
return "";
|
||||
}
|
||||
// Create a copy, don't share the array
|
||||
return new String(this);
|
||||
return new String(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue