< prev index next >

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

Print this page

        

@@ -24,11 +24,10 @@
  */
 
 package java.lang;
 
 import jdk.internal.math.FloatingDecimal;
-
 import java.util.Arrays;
 import java.util.Spliterator;
 import java.util.stream.IntStream;
 import java.util.stream.StreamSupport;
 

@@ -684,19 +683,14 @@
             s = "null";
         }
         checkRange(start, end, s.length());
         int len = end - start;
         ensureCapacityInternal(count + len);
-        if (s instanceof String) {
-            appendChars((String)s, start, end);
-        } else {
-            appendChars(s, start, end);
-        }
+        appendChars(s, start, end);
         return this;
     }
 
-
     /**
      * Appends the string representation of the {@code char} array
      * argument to this sequence.
      * <p>
      * The characters of the array argument are appended, in order, to

@@ -1747,39 +1741,10 @@
             StringUTF16.putCharsSB(this.value, count, s, off, end);
         }
         this.count = count + end - off;
     }
 
-    private final void appendChars(String s, int off, int end) {
-        if (isLatin1()) {
-            if (s.isLatin1()) {
-                System.arraycopy(s.value(), off, this.value, this.count, end - off);
-            } else {
-                // We might need to inflate, but do it as late as possible since
-                // the range of characters we're copying might all be latin1
-                byte[] val = this.value;
-                for (int i = off, j = count; i < end; i++) {
-                    char c = s.charAt(i);
-                    if (StringLatin1.canEncode(c)) {
-                        val[j++] = (byte) c;
-                    } else {
-                        count = j;
-                        inflate();
-                        System.arraycopy(s.value(), i << UTF16, this.value, j << UTF16, (end - i) << UTF16);
-                        count += end - i;
-                        return;
-                    }
-                }
-            }
-        } else if (s.isLatin1()) {
-            StringUTF16.putCharsSB(this.value, this.count, s, off, end);
-        } else { // both UTF16
-            System.arraycopy(s.value(), off << UTF16, this.value, this.count << UTF16, (end - off) << UTF16);
-        }
-        count += end - off;
-    }
-
     private final void appendChars(CharSequence s, int off, int end) {
         if (isLatin1()) {
             byte[] val = this.value;
             for (int i = off, j = count; i < end; i++) {
                 char c = s.charAt(i);
< prev index next >