8247605: Avoid array allocation when concatenating with empty string

Reviewed-by: redestad, plevart
This commit is contained in:
Tagir F. Valeev 2020-06-16 03:16:41 +00:00
parent e33ebc7f0a
commit 0a108f9ef2
2 changed files with 20 additions and 3 deletions

View file

@ -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);