mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8254082: AbstractStringBuilder.insert(int dstOffset, CharSequence s, int start, int end) is missing fast-path for String
Reviewed-by: redestad
This commit is contained in:
parent
4c86e46d75
commit
6eb25d7cb4
2 changed files with 37 additions and 13 deletions
|
@ -157,8 +157,8 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
return 0;
|
||||
}
|
||||
|
||||
byte val1[] = value;
|
||||
byte val2[] = another.value;
|
||||
byte[] val1 = value;
|
||||
byte[] val2 = another.value;
|
||||
int count1 = this.count;
|
||||
int count2 = another.count;
|
||||
|
||||
|
@ -734,7 +734,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
* if {@code offset < 0} or {@code len < 0}
|
||||
* or {@code offset+len > str.length}
|
||||
*/
|
||||
public AbstractStringBuilder append(char str[], int offset, int len) {
|
||||
public AbstractStringBuilder append(char[] str, int offset, int len) {
|
||||
int end = offset + len;
|
||||
checkRange(offset, end, str.length);
|
||||
ensureCapacityInternal(count + len);
|
||||
|
@ -1238,9 +1238,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
if (s == null) {
|
||||
s = "null";
|
||||
}
|
||||
if (s instanceof String) {
|
||||
return this.insert(dstOffset, (String)s);
|
||||
}
|
||||
return this.insert(dstOffset, s, 0, s.length());
|
||||
}
|
||||
|
||||
|
@ -1300,7 +1297,11 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
ensureCapacityInternal(count + len);
|
||||
shift(dstOffset, len);
|
||||
count += len;
|
||||
putCharsAt(dstOffset, s, start, end);
|
||||
if (s instanceof String) {
|
||||
putStringAt(dstOffset, (String) s, start, end);
|
||||
} else {
|
||||
putCharsAt(dstOffset, s, start, end);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -1558,9 +1559,8 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
public AbstractStringBuilder reverse() {
|
||||
byte[] val = this.value;
|
||||
int count = this.count;
|
||||
int coder = this.coder;
|
||||
int n = count - 1;
|
||||
if (COMPACT_STRINGS && coder == LATIN1) {
|
||||
if (isLatin1()) {
|
||||
for (int j = (n-1) >> 1; j >= 0; j--) {
|
||||
int k = n - j;
|
||||
byte cj = val[j];
|
||||
|
@ -1648,7 +1648,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
* @param dstBegin the char index, not offset of byte[]
|
||||
* @param coder the coder of dst[]
|
||||
*/
|
||||
void getBytes(byte dst[], int dstBegin, byte coder) {
|
||||
void getBytes(byte[] dst, int dstBegin, byte coder) {
|
||||
if (this.coder == coder) {
|
||||
System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
|
||||
} else { // this.coder == LATIN && coder == UTF16
|
||||
|
@ -1713,11 +1713,15 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||
}
|
||||
}
|
||||
|
||||
private final void putStringAt(int index, String str) {
|
||||
private void putStringAt(int index, String str, int off, int end) {
|
||||
if (getCoder() != str.coder()) {
|
||||
inflate();
|
||||
}
|
||||
str.getBytes(value, index, coder);
|
||||
str.getBytes(value, off, index, coder, end);
|
||||
}
|
||||
|
||||
private void putStringAt(int index, String str) {
|
||||
putStringAt(index, str, 0, str.length());
|
||||
}
|
||||
|
||||
private final void appendChars(char[] s, int off, int end) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue