< prev index next >
src/java.base/share/classes/java/lang/String.java
Print this page
rev 52913 : imported patch string
*** 1007,1020 ****
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String aString = (String)anObject;
! if (coder() == aString.coder()) {
! return isLatin1() ? StringLatin1.equals(value, aString.value)
! : StringUTF16.equals(value, aString.value);
! }
}
return false;
}
/**
--- 1007,1018 ----
if (this == anObject) {
return true;
}
if (anObject instanceof String) {
String aString = (String)anObject;
! if (sameCoder(aString))
! return StringLatin1.equals(value, aString.value);
}
return false;
}
/**
*** 1434,1444 ****
}
byte ta[] = value;
byte pa[] = prefix.value;
int po = 0;
int pc = pa.length;
! if (coder() == prefix.coder()) {
int to = isLatin1() ? toffset : toffset << 1;
while (po < pc) {
if (ta[to++] != pa[po++]) {
return false;
}
--- 1432,1442 ----
}
byte ta[] = value;
byte pa[] = prefix.value;
int po = 0;
int pc = pa.length;
! if (sameCoder(prefix)) {
int to = isLatin1() ? toffset : toffset << 1;
while (po < pc) {
if (ta[to++] != pa[po++]) {
return false;
}
*** 1455,1464 ****
--- 1453,1466 ----
}
}
return true;
}
+ private boolean sameCoder(String other) {
+ return COMPACT_STRINGS ? coder == other.coder : true;
+ }
+
/**
* Tests if this string starts with the specified prefix.
*
* @param prefix the prefix.
* @return {@code true} if the character sequence represented by the
*** 1662,1676 ****
* @param str the substring to search for.
* @return the index of the first occurrence of the specified substring,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(String str) {
! if (coder() == str.coder()) {
return isLatin1() ? StringLatin1.indexOf(value, str.value)
: StringUTF16.indexOf(value, str.value);
}
! if (coder() == LATIN1) { // str.coder == UTF16
return -1;
}
return StringUTF16.indexOfLatin1(value, str.value);
}
--- 1664,1678 ----
* @param str the substring to search for.
* @return the index of the first occurrence of the specified substring,
* or {@code -1} if there is no such occurrence.
*/
public int indexOf(String str) {
! if (sameCoder(str)) {
return isLatin1() ? StringLatin1.indexOf(value, str.value)
: StringUTF16.indexOf(value, str.value);
}
! if (isLatin1()) { // str.coder == UTF16
return -1;
}
return StringUTF16.indexOfLatin1(value, str.value);
}
*** 1940,1950 ****
public String concat(String str) {
int olen = str.length();
if (olen == 0) {
return this;
}
! if (coder() == str.coder()) {
byte[] val = this.value;
byte[] oval = str.value;
int len = val.length + oval.length;
byte[] buf = Arrays.copyOf(val, len);
System.arraycopy(oval, 0, buf, val.length, oval.length);
--- 1942,1952 ----
public String concat(String str) {
int olen = str.length();
if (olen == 0) {
return this;
}
! if (sameCoder(str)) {
byte[] val = this.value;
byte[] oval = str.value;
int len = val.length + oval.length;
byte[] buf = Arrays.copyOf(val, len);
System.arraycopy(oval, 0, buf, val.length, oval.length);
< prev index next >