--- old/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2015-05-28 12:50:43.767664507 +0200 +++ new/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2015-05-28 12:50:43.709664406 +0200 @@ -25,6 +25,7 @@ package java.lang; +import sun.misc.ConstantLengthCharSequence; import sun.misc.FloatingDecimal; import java.util.Arrays; import java.util.Spliterator; @@ -460,10 +461,24 @@ return this.append((String)s); if (s instanceof AbstractStringBuilder) return this.append((AbstractStringBuilder)s); + if (s instanceof ConstantLengthCharSequence) + return this.append((ConstantLengthCharSequence)s); return this.append(s, 0, s.length()); } + /** + * @since 1.9 + */ + AbstractStringBuilder append(ConstantLengthCharSequence ccs) { + // assert ccs != null; + int len = ccs.length(); + ensureCapacityInternal(count + len); + ccs.getChars(0, len, value, count); + count += len; + return this; + } + private AbstractStringBuilder appendNull() { int c = count; ensureCapacityInternal(c + 4); @@ -515,8 +530,12 @@ + s.length()); int len = end - start; ensureCapacityInternal(count + len); - for (int i = start, j = count; i < end; i++, j++) - value[j] = s.charAt(i); + if (s instanceof ConstantLengthCharSequence) { + ((ConstantLengthCharSequence)s).getChars(start, end, value, count); + } else { + for (int i = start, j = count; i < end; i++, j++) + value[j] = s.charAt(i); + } count += len; return this; } @@ -1077,10 +1096,28 @@ s = "null"; if (s instanceof String) return this.insert(dstOffset, (String)s); + if (s instanceof ConstantLengthCharSequence) + return this.insert(dstOffset, (ConstantLengthCharSequence)s); return this.insert(dstOffset, s, 0, s.length()); } /** + * @since 1.9 + */ + AbstractStringBuilder insert(int offset, ConstantLengthCharSequence ccs) { + if ((offset < 0) || (offset > length())) + throw new StringIndexOutOfBoundsException(offset); + if (ccs == null) + ccs = "null"; + int len = ccs.length(); + ensureCapacityInternal(count + len); + System.arraycopy(value, offset, value, offset + len, count - offset); + ccs.getChars(0, len, value, offset); + count += len; + return this; + } + + /** * Inserts a subsequence of the specified {@code CharSequence} into * this sequence. *

@@ -1124,8 +1161,8 @@ * {@code start} is greater than {@code end} or * {@code end} is greater than {@code s.length()} */ - public AbstractStringBuilder insert(int dstOffset, CharSequence s, - int start, int end) { + public AbstractStringBuilder insert(int dstOffset, CharSequence s, + int start, int end) { if (s == null) s = "null"; if ((dstOffset < 0) || (dstOffset > this.length())) @@ -1138,8 +1175,12 @@ ensureCapacityInternal(count + len); System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); - for (int i=start; i