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
@ -157,8 +157,8 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
byte val1[] = value;
|
byte[] val1 = value;
|
||||||
byte val2[] = another.value;
|
byte[] val2 = another.value;
|
||||||
int count1 = this.count;
|
int count1 = this.count;
|
||||||
int count2 = another.count;
|
int count2 = another.count;
|
||||||
|
|
||||||
@ -734,7 +734,7 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
* if {@code offset < 0} or {@code len < 0}
|
* if {@code offset < 0} or {@code len < 0}
|
||||||
* or {@code offset+len > str.length}
|
* 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;
|
int end = offset + len;
|
||||||
checkRange(offset, end, str.length);
|
checkRange(offset, end, str.length);
|
||||||
ensureCapacityInternal(count + len);
|
ensureCapacityInternal(count + len);
|
||||||
@ -1238,9 +1238,6 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
if (s == null) {
|
if (s == null) {
|
||||||
s = "null";
|
s = "null";
|
||||||
}
|
}
|
||||||
if (s instanceof String) {
|
|
||||||
return this.insert(dstOffset, (String)s);
|
|
||||||
}
|
|
||||||
return this.insert(dstOffset, s, 0, s.length());
|
return this.insert(dstOffset, s, 0, s.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1300,7 +1297,11 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
ensureCapacityInternal(count + len);
|
ensureCapacityInternal(count + len);
|
||||||
shift(dstOffset, len);
|
shift(dstOffset, len);
|
||||||
count += 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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1558,9 +1559,8 @@ abstract class AbstractStringBuilder implements Appendable, CharSequence {
|
|||||||
public AbstractStringBuilder reverse() {
|
public AbstractStringBuilder reverse() {
|
||||||
byte[] val = this.value;
|
byte[] val = this.value;
|
||||||
int count = this.count;
|
int count = this.count;
|
||||||
int coder = this.coder;
|
|
||||||
int n = count - 1;
|
int n = count - 1;
|
||||||
if (COMPACT_STRINGS && coder == LATIN1) {
|
if (isLatin1()) {
|
||||||
for (int j = (n-1) >> 1; j >= 0; j--) {
|
for (int j = (n-1) >> 1; j >= 0; j--) {
|
||||||
int k = n - j;
|
int k = n - j;
|
||||||
byte cj = val[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 dstBegin the char index, not offset of byte[]
|
||||||
* @param coder the coder of dst[]
|
* @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) {
|
if (this.coder == coder) {
|
||||||
System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
|
System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
|
||||||
} else { // this.coder == LATIN && coder == UTF16
|
} 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()) {
|
if (getCoder() != str.coder()) {
|
||||||
inflate();
|
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) {
|
private final void appendChars(char[] s, int off, int end) {
|
||||||
|
@ -3599,7 +3599,7 @@ public final class String
|
|||||||
* @param dstBegin the char index, not offset of byte[]
|
* @param dstBegin the char index, not offset of byte[]
|
||||||
* @param coder the coder of dst[]
|
* @param coder the coder of dst[]
|
||||||
*/
|
*/
|
||||||
void getBytes(byte dst[], int dstBegin, byte coder) {
|
void getBytes(byte[] dst, int dstBegin, byte coder) {
|
||||||
if (coder() == coder) {
|
if (coder() == coder) {
|
||||||
System.arraycopy(value, 0, dst, dstBegin << coder, value.length);
|
System.arraycopy(value, 0, dst, dstBegin << coder, value.length);
|
||||||
} else { // this.coder == LATIN && coder == UTF16
|
} else { // this.coder == LATIN && coder == UTF16
|
||||||
@ -3607,6 +3607,26 @@ public final class String
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy character bytes from this string into dst starting at dstBegin.
|
||||||
|
* This method doesn't perform any range checking.
|
||||||
|
*
|
||||||
|
* Invoker guarantees: dst is in UTF16 (inflate itself for asb), if two
|
||||||
|
* coders are different, and dst is big enough (range check)
|
||||||
|
*
|
||||||
|
* @param srcPos the char index, not offset of byte[]
|
||||||
|
* @param dstBegin the char index to start from
|
||||||
|
* @param coder the coder of dst[]
|
||||||
|
* @param length the amount of copied chars
|
||||||
|
*/
|
||||||
|
void getBytes(byte[] dst, int srcPos, int dstBegin, byte coder, int length) {
|
||||||
|
if (coder() == coder) {
|
||||||
|
System.arraycopy(value, srcPos, dst, dstBegin << coder, length << coder());
|
||||||
|
} else { // this.coder == LATIN && coder == UTF16
|
||||||
|
StringLatin1.inflate(value, srcPos, dst, dstBegin, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Package private constructor. Trailing Void argument is there for
|
* Package private constructor. Trailing Void argument is there for
|
||||||
* disambiguating it against other (public) constructors.
|
* disambiguating it against other (public) constructors.
|
||||||
|
Loading…
Reference in New Issue
Block a user