--- old/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2019-04-10 18:51:17.337807700 -0400 +++ new/src/java.base/share/classes/java/lang/AbstractStringBuilder.java 2019-04-10 18:51:16.421716100 -0400 @@ -92,57 +92,19 @@ } /** - * Constructs an AbstractStringBuilder that contains the same characters - * as the specified {@code String}. The initial capacity of - * the string builder is {@code 16} plus the length of the - * {@code String} argument. - * - * @param str the string to copy. + * Creates an AbstractStringBuilder with the specified coder and with + * the initial capacity equal to the smaller of (length + addition) + * and Integer.MAX_VALUE. */ - AbstractStringBuilder(String str) { - int length = str.length(); - int capacity = (length < Integer.MAX_VALUE - 16) - ? length + 16 : Integer.MAX_VALUE; - final byte initCoder = str.coder(); - coder = initCoder; - value = (initCoder == LATIN1) - ? new byte[capacity] : StringUTF16.newBytesFor(capacity); - append(str); - } - - /** - * Constructs an AbstractStringBuilder that contains the same characters - * as the specified {@code CharSequence}. The initial capacity of - * the string builder is {@code 16} plus the length of the - * {@code CharSequence} argument. - * - * @param seq the sequence to copy. - */ - AbstractStringBuilder(CharSequence seq) { - int length = seq.length(); + AbstractStringBuilder(byte coder, int length, int addition) { if (length < 0) { throw new NegativeArraySizeException("Negative length: " + length); } - int capacity = (length < Integer.MAX_VALUE - 16) - ? length + 16 : Integer.MAX_VALUE; - - final byte initCoder; - if (COMPACT_STRINGS) { - if (seq instanceof AbstractStringBuilder) { - initCoder = ((AbstractStringBuilder)seq).getCoder(); - } else if (seq instanceof String) { - initCoder = ((String)seq).coder(); - } else { - initCoder = LATIN1; - } - } else { - initCoder = UTF16; - } - - coder = initCoder; - value = (initCoder == LATIN1) + this.coder = coder; + int capacity = (length < Integer.MAX_VALUE - addition) + ? length + addition : Integer.MAX_VALUE; + value = (coder == LATIN1) ? new byte[capacity] : StringUTF16.newBytesFor(capacity); - append(seq); } /**