# HG changeset patch # User Jaroslav Tulach # Date 1349050232 25200 # Node ID 06bd18f34608bde47cf02c5c9a5a22525801fad7 # Parent 54179e9c6a2f4b2cbaac4572fe539f68f86fb2db Centralize all calls to System.arraycopy under one method in String diff -r 54179e9c6a2f -r 06bd18f34608 emul/src/main/java/java/lang/AbstractStringBuilder.java --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Sun Sep 30 14:37:39 2012 -0700 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java Sun Sep 30 17:10:32 2012 -0700 @@ -350,7 +350,7 @@ throw new StringIndexOutOfBoundsException(srcEnd); if (srcBegin > srcEnd) throw new StringIndexOutOfBoundsException("srcBegin > srcEnd"); - System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); + String.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin); } /** @@ -500,7 +500,7 @@ public AbstractStringBuilder append(char[] str) { int len = str.length; ensureCapacityInternal(count + len); - System.arraycopy(str, 0, value, count, len); + String.arraycopy(str, 0, value, count, len); count += len; return this; } @@ -530,7 +530,7 @@ public AbstractStringBuilder append(char str[], int offset, int len) { if (len > 0) // let arraycopy report AIOOBE for len < 0 ensureCapacityInternal(count + len); - System.arraycopy(str, offset, value, count, len); + String.arraycopy(str, offset, value, count, len); count += len; return this; } @@ -693,7 +693,7 @@ throw new StringIndexOutOfBoundsException(); int len = end - start; if (len > 0) { - System.arraycopy(value, start+len, value, start, count-end); + String.arraycopy(value, start+len, value, start, count-end); count -= len; } return this; @@ -755,7 +755,7 @@ public AbstractStringBuilder deleteCharAt(int index) { if ((index < 0) || (index >= count)) throw new StringIndexOutOfBoundsException(index); - System.arraycopy(value, index+1, value, index, count-index-1); + String.arraycopy(value, index+1, value, index, count-index-1); count--; return this; } @@ -793,7 +793,7 @@ int newCount = count + len - (end - start); ensureCapacityInternal(newCount); - System.arraycopy(value, end, value, start + len, count - end); + String.arraycopy(value, end, value, start + len, count - end); str.getChars(value, start); count = newCount; return this; @@ -899,8 +899,8 @@ "offset " + offset + ", len " + len + ", str.length " + str.length); ensureCapacityInternal(count + len); - System.arraycopy(value, index, value, index + len, count - index); - System.arraycopy(str, offset, value, index, len); + String.arraycopy(value, index, value, index + len, count - index); + String.arraycopy(str, offset, value, index, len); count += len; return this; } @@ -966,7 +966,7 @@ str = "null"; int len = str.length(); ensureCapacityInternal(count + len); - System.arraycopy(value, offset, value, offset + len, count - offset); + String.arraycopy(value, offset, value, offset + len, count - offset); str.getChars(value, offset); count += len; return this; @@ -1001,8 +1001,8 @@ throw new StringIndexOutOfBoundsException(offset); int len = str.length; ensureCapacityInternal(count + len); - System.arraycopy(value, offset, value, offset + len, count - offset); - System.arraycopy(str, 0, value, offset, len); + String.arraycopy(value, offset, value, offset + len, count - offset); + String.arraycopy(str, 0, value, offset, len); count += len; return this; } @@ -1092,7 +1092,7 @@ + s.length()); int len = end - start; ensureCapacityInternal(count + len); - System.arraycopy(value, dstOffset, value, dstOffset + len, + String.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); for (int i=start; i srcEnd) { throw new StringIndexOutOfBoundsException(srcEnd - srcBegin); } - System.arraycopy(value, offset + srcBegin, dst, dstBegin, + arraycopy(value, offset + srcBegin, dst, dstBegin, srcEnd - srcBegin); } @@ -2435,7 +2435,7 @@ // * is the write location in result */ // // /* Just copy the first few lowerCase characters. */ -// System.arraycopy(value, offset, result, 0, firstUpper); +// arraycopy(value, offset, result, 0, firstUpper); // // String lang = locale.getLanguage(); // boolean localeDependent = @@ -2481,7 +2481,7 @@ // int mapLen = lowerCharArray.length; // if (mapLen > srcCount) { // char[] result2 = new char[result.length + mapLen - srcCount]; -// System.arraycopy(result, 0, result2, 0, +// arraycopy(result, 0, result2, 0, // i + resultOffset); // result = result2; // } @@ -2602,7 +2602,7 @@ * is the write location in result * /* Just copy the first few upperCase characters. * - System.arraycopy(value, offset, result, 0, firstLower); + arraycopy(value, offset, result, 0, firstLower); String lang = locale.getLanguage(); boolean localeDependent = @@ -2645,7 +2645,7 @@ int mapLen = upperCharArray.length; if (mapLen > srcCount) { char[] result2 = new char[result.length + mapLen - srcCount]; - System.arraycopy(result, 0, result2, 0, + arraycopy(result, 0, result2, 0, i + resultOffset); result = result2; } @@ -3029,15 +3029,20 @@ throw new IllegalArgumentException(from + " > " + to); } char[] copy = new char[newLength]; - System.arraycopy(original, from, copy, 0, + arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; } static char[] copyOf(char[] original, int newLength) { char[] copy = new char[newLength]; - System.arraycopy(original, 0, copy, 0, + arraycopy(original, 0, copy, 0, Math.min(original.length, newLength)); return copy; } + static void arraycopy( + char[] value, int srcBegin, char[] dst, int dstBegin, int count + ) { + System.arraycopy(value, srcBegin, dst, dstBegin, count); + } }