Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8273100: Improve AbstractStringBuilder.append(String) when using Comp…
…actStrings

Reviewed-by: rriggs, alanb
  • Loading branch information
cl4es committed Aug 31, 2021
1 parent 9732fbe commit 98fa533
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/java.base/share/classes/java/lang/AbstractStringBuilder.java
Expand Up @@ -603,9 +603,7 @@ AbstractStringBuilder append(AbstractStringBuilder asb) {
}
int len = asb.length();
ensureCapacityInternal(count + len);
if (getCoder() != asb.getCoder()) {
inflate();
}
inflateIfNeededFor(asb);
asb.getBytes(value, count, coder);
count += len;
return this;
Expand Down Expand Up @@ -1712,15 +1710,26 @@ private final void putCharsAt(int index, CharSequence s, int off, int end) {
}
}

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) {
Expand Down

1 comment on commit 98fa533

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.