Merge
authorneliasso
Tue, 01 Dec 2015 19:18:46 +0100
changeset 34518 b46a55b62834
parent 34377 88b91bf5db89 (current diff)
parent 34517 c6e795a80c80 (diff)
child 34519 89dab2d4f7b9
Merge
jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java
--- a/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java	Mon Nov 30 13:55:09 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/AbstractStringBuilder.java	Tue Dec 01 19:18:46 2015 +0100
@@ -177,7 +177,7 @@
             return;
         }
         byte[] buf = StringUTF16.newBytesFor(value.length);
-        StringLatin1.inflateSB(value, buf, 0, count);
+        StringLatin1.inflate(value, 0, buf, 0, count);
         this.value = buf;
         this.coder = UTF16;
     }
@@ -414,9 +414,9 @@
         int n = srcEnd - srcBegin;
         checkRange(dstBegin, dstBegin + n, dst.length);
         if (isLatin1()) {
-            StringLatin1.getCharsSB(value, srcBegin, srcEnd, dst, dstBegin);
+            StringLatin1.getChars(value, srcBegin, srcEnd, dst, dstBegin);
         } else {
-            StringUTF16.getCharsSB(value, srcBegin, srcEnd, dst, dstBegin);
+            StringUTF16.getChars(value, srcBegin, srcEnd, dst, dstBegin);
         }
     }
 
@@ -980,7 +980,7 @@
         if (isLatin1()) {
             return StringLatin1.newString(value, start, end - start);
         }
-        return StringUTF16.newStringSB(value, start, end - start);
+        return StringUTF16.newString(value, start, end - start);
     }
 
     private void shift(int offset, int n) {
@@ -1576,7 +1576,7 @@
         if (this.coder == coder) {
             System.arraycopy(value, 0, dst, dstBegin << coder, count << coder);
         } else {        // this.coder == LATIN && coder == UTF16
-            StringLatin1.inflateSB(value, dst, dstBegin, count);
+            StringLatin1.inflate(value, 0, dst, dstBegin, count);
         }
     }
 
@@ -1641,10 +1641,7 @@
         if (getCoder() != str.coder()) {
             inflate();
         }
-        byte[] val = this.value;
-        byte coder = this.coder;
-        checkOffset(index + str.length(), val.length >> coder);
-        str.getBytes(val, index, coder);
+        str.getBytes(value, index, coder);
     }
 
     private final void appendChars(char[] s, int off, int end) {
--- a/jdk/src/java.base/share/classes/java/lang/String.java	Mon Nov 30 13:55:09 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/String.java	Tue Dec 01 19:18:46 2015 +0100
@@ -1720,7 +1720,6 @@
      */
     static int indexOf(byte[] src, byte srcCoder, int srcCount,
                        String tgtStr, int fromIndex) {
-
         byte[] tgt    = tgtStr.value;
         byte tgtCoder = tgtStr.coder();
         int tgtCount  = tgtStr.length();
@@ -3103,7 +3102,7 @@
      *          If {@code offset} is negative, {@code count} is negative,
      *          or {@code offset} is greater than {@code length - count}
      */
-    private static void checkBoundsOffCount(int offset, int count, int length) {
+    static void checkBoundsOffCount(int offset, int count, int length) {
         if (offset < 0 || count < 0 || offset > length - count) {
             throw new StringIndexOutOfBoundsException(
                 "offset " + offset + ", count " + count + ", length " + length);
--- a/jdk/src/java.base/share/classes/java/lang/StringBuilder.java	Mon Nov 30 13:55:09 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/StringBuilder.java	Tue Dec 01 19:18:46 2015 +0100
@@ -413,7 +413,7 @@
     public String toString() {
         // Create a copy, don't share the array
         return isLatin1() ? StringLatin1.newString(value, 0, count)
-                          : StringUTF16.newStringSB(value, 0, count);
+                          : StringUTF16.newString(value, 0, count);
     }
 
     /**
--- a/jdk/src/java.base/share/classes/java/lang/StringLatin1.java	Mon Nov 30 13:55:09 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/StringLatin1.java	Tue Dec 01 19:18:46 2015 +0100
@@ -36,6 +36,7 @@
 import static java.lang.String.LATIN1;
 import static java.lang.String.UTF16;
 import static java.lang.String.checkOffset;
+import static java.lang.String.checkBoundsOffCount;
 
 final class StringLatin1 {
 
@@ -523,6 +524,8 @@
     // inflatedCopy byte[] -> byte[]
     @HotSpotIntrinsicCandidate
     public static void inflate(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
+        // We need a range check here because 'putChar' has no checks
+        checkBoundsOffCount(dstOff, len, dst.length);
         for (int i = 0; i < len; i++) {
             StringUTF16.putChar(dst, dstOff++, src[srcOff++] & 0xff);
         }
@@ -584,17 +587,4 @@
             return cs;
         }
     }
-
-    ////////////////////////////////////////////////////////////////
-
-    public static void getCharsSB(byte[] val, int srcBegin, int srcEnd, char dst[], int dstBegin) {
-        checkOffset(srcEnd, val.length);
-        getChars(val, srcBegin, srcEnd, dst, dstBegin);
-    }
-
-    public static void inflateSB(byte[] val, byte[] dst, int dstOff, int count) {
-        checkOffset(count, val.length);
-        checkOffset(dstOff + count, dst.length >> 1);  // dst is utf16
-        inflate(val, 0, dst, dstOff, count);
-    }
 }
--- a/jdk/src/java.base/share/classes/java/lang/StringUTF16.java	Mon Nov 30 13:55:09 2015 -0800
+++ b/jdk/src/java.base/share/classes/java/lang/StringUTF16.java	Tue Dec 01 19:18:46 2015 +0100
@@ -35,6 +35,7 @@
 import static java.lang.String.LATIN1;
 import static java.lang.String.checkIndex;
 import static java.lang.String.checkOffset;
+import static java.lang.String.checkBoundsOffCount;
 
 final class StringUTF16 {
 
@@ -156,6 +157,8 @@
     // compressedCopy byte[] -> byte[]
     @HotSpotIntrinsicCandidate
     public static int compress(byte[] src, int srcOff, byte[] dst, int dstOff, int len) {
+        // We need a range check here because 'getChar' has no checks
+        checkBoundsOffCount(srcOff, len, src.length);
         for (int i = 0; i < len; i++) {
             int c = getChar(src, srcOff++);
             if (c >>> 8 != 0) {
@@ -200,6 +203,8 @@
 
     @HotSpotIntrinsicCandidate
     public static void getChars(byte[] value, int srcBegin, int srcEnd, char dst[], int dstBegin) {
+        // We need a range check here because 'getChar' has no checks
+        checkBoundsOffCount(srcBegin, srcEnd - srcBegin, value.length);
         for (int i = srcBegin; i < srcEnd; i++) {
             dst[dstBegin++] = getChar(value, i);
         }
@@ -909,11 +914,6 @@
 
     ////////////////////////////////////////////////////////////////
 
-    public static void getCharsSB(byte[] val, int srcBegin, int srcEnd, char dst[], int dstBegin) {
-        checkOffset(srcEnd, val.length >> 1);
-        getChars(val, srcBegin, srcEnd, dst, dstBegin);
-    }
-
     public static void putCharSB(byte[] val, int index, int c) {
         checkIndex(index, val.length >> 1);
         putChar(val, index, c);
@@ -946,11 +946,6 @@
         return codePointCount(val, beginIndex, endIndex);
     }
 
-    public static String newStringSB(byte[] val, int index, int len) {
-        checkOffset(index + len, val.length >> 1);
-        return newString(val, index, len);
-    }
-
     ////////////////////////////////////////////////////////////////
 
     private static native boolean isBigEndian();