--- old/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2017-03-22 23:53:50.000000000 +0300 +++ new/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2017-03-22 23:53:49.000000000 +0300 @@ -36,6 +36,7 @@ import static java.lang.String.LATIN1; import static java.lang.String.checkIndex; import static java.lang.String.checkOffset; +import static java.lang.String.checkBoundsBeginEnd; /** * A mutable sequence of characters. @@ -307,6 +308,8 @@ * sequence. */ public int codePointAt(int index) { + int count = this.count; + byte[] value = this.value; checkIndex(index, count); if (isLatin1()) { return value[index] & 0xff; @@ -560,7 +563,7 @@ val[count++] = 'l'; val[count++] = 'l'; } else { - checkOffset(count + 4, val.length >> 1); + checkBoundsBeginEnd(count, count + 4, val.length >> 1); StringUTF16.putChar(val, count++, 'n'); StringUTF16.putChar(val, count++, 'u'); StringUTF16.putChar(val, count++, 'l'); @@ -695,13 +698,13 @@ } } else { if (b) { - checkOffset(count + 4, val.length >> 1); + checkBoundsBeginEnd(count, count + 4, val.length >> 1); StringUTF16.putChar(val, count++, 't'); StringUTF16.putChar(val, count++, 'r'); StringUTF16.putChar(val, count++, 'u'); StringUTF16.putChar(val, count++, 'e'); } else { - checkOffset(count + 5, val.length >> 1); + checkBoundsBeginEnd(count, count + 5, val.length >> 1); StringUTF16.putChar(val, count++, 'f'); StringUTF16.putChar(val, count++, 'a'); StringUTF16.putChar(val, count++, 'l'); @@ -755,16 +758,17 @@ * @return a reference to this object. */ public AbstractStringBuilder append(int i) { + int count = this.count; int spaceNeeded = count + Integer.stringSize(i); ensureCapacityInternal(spaceNeeded); if (isLatin1()) { Integer.getChars(i, spaceNeeded, value); } else { byte[] val = this.value; - checkOffset(spaceNeeded, val.length >> 1); + checkBoundsBeginEnd(count, spaceNeeded, val.length >> 1); Integer.getCharsUTF16(i, spaceNeeded, val); } - count = spaceNeeded; + this.count = spaceNeeded; return this; } @@ -781,16 +785,17 @@ * @return a reference to this object. */ public AbstractStringBuilder append(long l) { + int count = this.count; int spaceNeeded = count + Long.stringSize(l); ensureCapacityInternal(spaceNeeded); if (isLatin1()) { Long.getChars(l, spaceNeeded, value); } else { byte[] val = this.value; - checkOffset(spaceNeeded, val.length >> 1); + checkBoundsBeginEnd(count, spaceNeeded, val.length >> 1); Long.getCharsUTF16(l, spaceNeeded, val); } - count = spaceNeeded; + this.count = spaceNeeded; return this; } @@ -843,6 +848,7 @@ * greater than {@code end}. */ public AbstractStringBuilder delete(int start, int end) { + int count = this.count; if (end > count) { end = count; } @@ -850,7 +856,7 @@ int len = end - start; if (len > 0) { shift(end, -len); - count -= len; + this.count = count - len; } return this; } @@ -925,6 +931,7 @@ * greater than {@code end}. */ public AbstractStringBuilder replace(int start, int end, String str) { + int count = this.count; if (end > count) { end = count; } @@ -933,7 +940,7 @@ int newCount = count + len - (end - start); ensureCapacityInternal(newCount); shift(end, newCount - count); - count = newCount; + this.count = newCount; putStringAt(start, str); return this; } @@ -1422,6 +1429,10 @@ * or {@code -1} if there is no such occurrence. */ public int indexOf(String str, int fromIndex) { + byte[] value = this.value; + int count = this.count; + byte coder = this.coder; + checkOffset(count, value.length >> coder); return String.indexOf(value, coder, count, str, fromIndex); } @@ -1462,6 +1473,10 @@ * or {@code -1} if there is no such occurrence. */ public int lastIndexOf(String str, int fromIndex) { + byte[] value = this.value; + int count = this.count; + byte coder = this.coder; + checkOffset(count, value.length >> coder); return String.lastIndexOf(value, coder, count, str, fromIndex); }