Centralize all calls to System.arraycopy under one method in String emul
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sun, 30 Sep 2012 17:10:32 -0700
branchemul
changeset 7206bd18f34608
parent 71 54179e9c6a2f
child 73 bf8e571de593
Centralize all calls to System.arraycopy under one method in String
emul/src/main/java/java/lang/AbstractStringBuilder.java
emul/src/main/java/java/lang/String.java
     1.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java	Sun Sep 30 14:37:39 2012 -0700
     1.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java	Sun Sep 30 17:10:32 2012 -0700
     1.3 @@ -350,7 +350,7 @@
     1.4              throw new StringIndexOutOfBoundsException(srcEnd);
     1.5          if (srcBegin > srcEnd)
     1.6              throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
     1.7 -        System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
     1.8 +        String.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
     1.9      }
    1.10  
    1.11      /**
    1.12 @@ -500,7 +500,7 @@
    1.13      public AbstractStringBuilder append(char[] str) {
    1.14          int len = str.length;
    1.15          ensureCapacityInternal(count + len);
    1.16 -        System.arraycopy(str, 0, value, count, len);
    1.17 +        String.arraycopy(str, 0, value, count, len);
    1.18          count += len;
    1.19          return this;
    1.20      }
    1.21 @@ -530,7 +530,7 @@
    1.22      public AbstractStringBuilder append(char str[], int offset, int len) {
    1.23          if (len > 0)                // let arraycopy report AIOOBE for len < 0
    1.24              ensureCapacityInternal(count + len);
    1.25 -        System.arraycopy(str, offset, value, count, len);
    1.26 +        String.arraycopy(str, offset, value, count, len);
    1.27          count += len;
    1.28          return this;
    1.29      }
    1.30 @@ -693,7 +693,7 @@
    1.31              throw new StringIndexOutOfBoundsException();
    1.32          int len = end - start;
    1.33          if (len > 0) {
    1.34 -            System.arraycopy(value, start+len, value, start, count-end);
    1.35 +            String.arraycopy(value, start+len, value, start, count-end);
    1.36              count -= len;
    1.37          }
    1.38          return this;
    1.39 @@ -755,7 +755,7 @@
    1.40      public AbstractStringBuilder deleteCharAt(int index) {
    1.41          if ((index < 0) || (index >= count))
    1.42              throw new StringIndexOutOfBoundsException(index);
    1.43 -        System.arraycopy(value, index+1, value, index, count-index-1);
    1.44 +        String.arraycopy(value, index+1, value, index, count-index-1);
    1.45          count--;
    1.46          return this;
    1.47      }
    1.48 @@ -793,7 +793,7 @@
    1.49          int newCount = count + len - (end - start);
    1.50          ensureCapacityInternal(newCount);
    1.51  
    1.52 -        System.arraycopy(value, end, value, start + len, count - end);
    1.53 +        String.arraycopy(value, end, value, start + len, count - end);
    1.54          str.getChars(value, start);
    1.55          count = newCount;
    1.56          return this;
    1.57 @@ -899,8 +899,8 @@
    1.58                  "offset " + offset + ", len " + len + ", str.length "
    1.59                  + str.length);
    1.60          ensureCapacityInternal(count + len);
    1.61 -        System.arraycopy(value, index, value, index + len, count - index);
    1.62 -        System.arraycopy(str, offset, value, index, len);
    1.63 +        String.arraycopy(value, index, value, index + len, count - index);
    1.64 +        String.arraycopy(str, offset, value, index, len);
    1.65          count += len;
    1.66          return this;
    1.67      }
    1.68 @@ -966,7 +966,7 @@
    1.69              str = "null";
    1.70          int len = str.length();
    1.71          ensureCapacityInternal(count + len);
    1.72 -        System.arraycopy(value, offset, value, offset + len, count - offset);
    1.73 +        String.arraycopy(value, offset, value, offset + len, count - offset);
    1.74          str.getChars(value, offset);
    1.75          count += len;
    1.76          return this;
    1.77 @@ -1001,8 +1001,8 @@
    1.78              throw new StringIndexOutOfBoundsException(offset);
    1.79          int len = str.length;
    1.80          ensureCapacityInternal(count + len);
    1.81 -        System.arraycopy(value, offset, value, offset + len, count - offset);
    1.82 -        System.arraycopy(str, 0, value, offset, len);
    1.83 +        String.arraycopy(value, offset, value, offset + len, count - offset);
    1.84 +        String.arraycopy(str, 0, value, offset, len);
    1.85          count += len;
    1.86          return this;
    1.87      }
    1.88 @@ -1092,7 +1092,7 @@
    1.89                  + s.length());
    1.90          int len = end - start;
    1.91          ensureCapacityInternal(count + len);
    1.92 -        System.arraycopy(value, dstOffset, value, dstOffset + len,
    1.93 +        String.arraycopy(value, dstOffset, value, dstOffset + len,
    1.94                           count - dstOffset);
    1.95          for (int i=start; i<end; i++)
    1.96              value[dstOffset++] = s.charAt(i);
    1.97 @@ -1144,7 +1144,7 @@
    1.98       */
    1.99      public AbstractStringBuilder insert(int offset, char c) {
   1.100          ensureCapacityInternal(count + 1);
   1.101 -        System.arraycopy(value, offset, value, offset + 1, count - offset);
   1.102 +        String.arraycopy(value, offset, value, offset + 1, count - offset);
   1.103          value[offset] = c;
   1.104          count += 1;
   1.105          return this;
     2.1 --- a/emul/src/main/java/java/lang/String.java	Sun Sep 30 14:37:39 2012 -0700
     2.2 +++ b/emul/src/main/java/java/lang/String.java	Sun Sep 30 17:10:32 2012 -0700
     2.3 @@ -811,7 +811,7 @@
     2.4       * This method doesn't perform any range checking.
     2.5       */
     2.6      void getChars(char dst[], int dstBegin) {
     2.7 -        System.arraycopy(value, offset, dst, dstBegin, count);
     2.8 +        arraycopy(value, offset, dst, dstBegin, count);
     2.9      }
    2.10  
    2.11      /**
    2.12 @@ -854,7 +854,7 @@
    2.13          if (srcBegin > srcEnd) {
    2.14              throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
    2.15          }
    2.16 -        System.arraycopy(value, offset + srcBegin, dst, dstBegin,
    2.17 +        arraycopy(value, offset + srcBegin, dst, dstBegin,
    2.18               srcEnd - srcBegin);
    2.19      }
    2.20  
    2.21 @@ -2435,7 +2435,7 @@
    2.22  //                                    * is the write location in result */
    2.23  //
    2.24  //        /* Just copy the first few lowerCase characters. */
    2.25 -//        System.arraycopy(value, offset, result, 0, firstUpper);
    2.26 +//        arraycopy(value, offset, result, 0, firstUpper);
    2.27  //
    2.28  //        String lang = locale.getLanguage();
    2.29  //        boolean localeDependent =
    2.30 @@ -2481,7 +2481,7 @@
    2.31  //                int mapLen = lowerCharArray.length;
    2.32  //                if (mapLen > srcCount) {
    2.33  //                    char[] result2 = new char[result.length + mapLen - srcCount];
    2.34 -//                    System.arraycopy(result, 0, result2, 0,
    2.35 +//                    arraycopy(result, 0, result2, 0,
    2.36  //                        i + resultOffset);
    2.37  //                    result = result2;
    2.38  //                }
    2.39 @@ -2602,7 +2602,7 @@
    2.40                                      * is the write location in result *
    2.41  
    2.42          /* Just copy the first few upperCase characters. *
    2.43 -        System.arraycopy(value, offset, result, 0, firstLower);
    2.44 +        arraycopy(value, offset, result, 0, firstLower);
    2.45  
    2.46          String lang = locale.getLanguage();
    2.47          boolean localeDependent =
    2.48 @@ -2645,7 +2645,7 @@
    2.49                  int mapLen = upperCharArray.length;
    2.50                  if (mapLen > srcCount) {
    2.51                      char[] result2 = new char[result.length + mapLen - srcCount];
    2.52 -                    System.arraycopy(result, 0, result2, 0,
    2.53 +                    arraycopy(result, 0, result2, 0,
    2.54                          i + resultOffset);
    2.55                      result = result2;
    2.56                  }
    2.57 @@ -3029,15 +3029,20 @@
    2.58              throw new IllegalArgumentException(from + " > " + to);
    2.59          }
    2.60          char[] copy = new char[newLength];
    2.61 -        System.arraycopy(original, from, copy, 0,
    2.62 +        arraycopy(original, from, copy, 0,
    2.63              Math.min(original.length - from, newLength));
    2.64          return copy;
    2.65      }
    2.66      static char[] copyOf(char[] original, int newLength) {
    2.67          char[] copy = new char[newLength];
    2.68 -        System.arraycopy(original, 0, copy, 0,
    2.69 +        arraycopy(original, 0, copy, 0,
    2.70              Math.min(original.length, newLength));
    2.71          return copy;
    2.72      }
    2.73 +    static void arraycopy(
    2.74 +        char[] value, int srcBegin, char[] dst, int dstBegin, int count
    2.75 +    ) {
    2.76 +        System.arraycopy(value, srcBegin, dst, dstBegin, count);
    2.77 +    }
    2.78  
    2.79  }