< prev index next >
src/java.base/share/classes/java/lang/String.java
Print this page
rev 58157 : 8240094: Optimize empty substring handling
Reviewed-by: redestad, igerasim, jlaskey
Contributed-by: sergei.tsypanov@yandex.ru
*** 1817,1827 ****
* is the string being searched for.
*
* @param src the characters being searched.
* @param srcCoder coder handles the mapping between bytes/chars
* @param srcCount count of the source string.
! * @param tgt the characters being searched for.
* @param fromIndex the index to begin searching from.
*/
static int lastIndexOf(byte[] src, byte srcCoder, int srcCount,
String tgtStr, int fromIndex) {
byte[] tgt = tgtStr.value;
--- 1817,1827 ----
* is the string being searched for.
*
* @param src the characters being searched.
* @param srcCoder coder handles the mapping between bytes/chars
* @param srcCount count of the source string.
! * @param tgtStr the characters being searched for.
* @param fromIndex the index to begin searching from.
*/
static int lastIndexOf(byte[] src, byte srcCoder, int srcCount,
String tgtStr, int fromIndex) {
byte[] tgt = tgtStr.value;
*** 1898,1911 ****
* {@code endIndex}.
*/
public String substring(int beginIndex, int endIndex) {
int length = length();
checkBoundsBeginEnd(beginIndex, endIndex, length);
- int subLen = endIndex - beginIndex;
if (beginIndex == 0 && endIndex == length) {
return this;
}
return isLatin1() ? StringLatin1.newString(value, beginIndex, subLen)
: StringUTF16.newString(value, beginIndex, subLen);
}
/**
--- 1898,1911 ----
* {@code endIndex}.
*/
public String substring(int beginIndex, int endIndex) {
int length = length();
checkBoundsBeginEnd(beginIndex, endIndex, length);
if (beginIndex == 0 && endIndex == length) {
return this;
}
+ int subLen = endIndex - beginIndex;
return isLatin1() ? StringLatin1.newString(value, beginIndex, subLen)
: StringUTF16.newString(value, beginIndex, subLen);
}
/**
< prev index next >