mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8247605: Avoid array allocation when concatenating with empty string
Reviewed-by: redestad, plevart
This commit is contained in:
parent
e33ebc7f0a
commit
0a108f9ef2
2 changed files with 20 additions and 3 deletions
|
@ -406,6 +406,14 @@ final class StringConcatHelper {
|
|||
static String simpleConcat(Object first, Object second) {
|
||||
String s1 = stringOf(first);
|
||||
String s2 = stringOf(second);
|
||||
if (s1.isEmpty()) {
|
||||
// newly created string required, see JLS 15.18.1
|
||||
return new String(s2);
|
||||
}
|
||||
if (s2.isEmpty()) {
|
||||
// newly created string required, see JLS 15.18.1
|
||||
return new String(s1);
|
||||
}
|
||||
// start "mixing" in length and coder or arguments, order is not
|
||||
// important
|
||||
long indexCoder = mix(initialCoder(), s1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue