8273100: Improve AbstractStringBuilder.append(String) when using CompactStrings

Reviewed-by: rriggs, alanb
This commit is contained in:
Claes Redestad 2021-08-31 11:32:33 +00:00
parent 9732fbe428
commit 98fa53357a

View File

@ -603,9 +603,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
}
int len = asb.length();
ensureCapacityInternal(count + len);
if (getCoder() != asb.getCoder()) {
inflate();
}
inflateIfNeededFor(asb);
asb.getBytes(value, count, coder);
count += len;
return this;
@ -1712,15 +1710,26 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
}
}
private void putStringAt(int index, String str, int off, int end) {
if (getCoder() != str.coder()) {
private void inflateIfNeededFor(String input) {
if (COMPACT_STRINGS && (coder != input.coder())) {
inflate();
}
}
private void inflateIfNeededFor(AbstractStringBuilder input) {
if (COMPACT_STRINGS && (coder != input.getCoder())) {
inflate();
}
}
private void putStringAt(int index, String str, int off, int end) {
inflateIfNeededFor(str);
str.getBytes(value, off, index, coder, end - off);
}
private void putStringAt(int index, String str) {
putStringAt(index, str, 0, str.length());
inflateIfNeededFor(str);
str.getBytes(value, index, coder);
}
private final void appendChars(char[] s, int off, int end) {