< prev index next >

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Print this page

        

*** 23,32 **** --- 23,33 ---- * questions. */ package java.lang; + import sun.misc.ConstantLengthCharSequence; import sun.misc.FloatingDecimal; import java.util.Arrays; import java.util.Spliterator; import java.util.stream.IntStream; import java.util.stream.StreamSupport;
*** 458,471 **** --- 459,486 ---- return appendNull(); if (s instanceof String) 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); final char[] value = this.value; value[c++] = 'n';
*** 513,524 **** --- 528,543 ---- throw new IndexOutOfBoundsException( "start " + start + ", end " + end + ", s.length() " + s.length()); int len = end - start; ensureCapacityInternal(count + len); + 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; } /**
*** 1075,1088 **** --- 1094,1125 ---- public AbstractStringBuilder insert(int dstOffset, CharSequence s) { if (s == null) 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. * <p> * The subsequence of the argument {@code s} specified by * {@code start} and {@code end} are inserted,
*** 1136,1147 **** + s.length()); int len = end - start; ensureCapacityInternal(count + len); System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); ! for (int i=start; i<end; i++) value[dstOffset++] = s.charAt(i); count += len; return this; } /** --- 1173,1188 ---- + s.length()); int len = end - start; ensureCapacityInternal(count + len); System.arraycopy(value, dstOffset, value, dstOffset + len, count - dstOffset); ! if (s instanceof ConstantLengthCharSequence) { ! ((ConstantLengthCharSequence)s).getChars(start, end, value, dstOffset); ! } else { ! for (int i = start; i < end; i++) value[dstOffset++] = s.charAt(i); + } count += len; return this; } /**
< prev index next >