--- old/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2016-12-09 08:31:41.461375054 +0100 +++ new/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2016-12-09 08:31:41.358375828 +0100 @@ -547,6 +547,10 @@ if (s instanceof AbstractStringBuilder) { return this.append((AbstractStringBuilder)s); } + if (s instanceof CharRepetitions) { + CharRepetitions cr = (CharRepetitions) s; + return this.appendN(cr.getChar(), cr.length()); + } return this.append(s, 0, s.length()); } @@ -741,6 +745,53 @@ } return this; } + + /** + * Appends {@code n} copies of the string representation of + * the {@code char} argument to this sequence. + *

+ * The first argument is appended to the contents of this + * sequence specified amount of times. + * The length of this sequence increases by {@code n}. + *

+ * The overall effect is exactly as if the first argument + * were converted to a string by the method + * {@link String#valueOf(char)}, and the character in that + * string were then {@link #append(String) appended} to this + * character sequence {@code n} times. + * + * @param c a {@code char}. + * @param n a number of copies to append. + * @return a reference to this object. + * @throws IllegalArgumentException if {@code n < 0}. + */ + @Override + public AbstractStringBuilder appendN(char c, int n) { + if (n <= 0) { + if (n < 0) { + throw new IllegalArgumentException( + "Negative number of copies: " + n); + } + } else { + int count = this.count; + ensureCapacityInternal(count + n); + if (isLatin1() && StringLatin1.canEncode(c)) { + byte b = (byte)c; + do { + value[count++] = b; + } while (--n > 0); + } else { + if (isLatin1()) { + inflate(); + } + do { + StringUTF16.putCharSB(value, count++, c); + } while (--n > 0); + } + this.count = count; + } + return this; + } /** * Appends the string representation of the {@code int}