jdk/src/share/classes/java/lang/AbstractStringBuilder.java
changeset 5986 04eb44085c00
parent 5627 e636ac7a63a4
child 6295 91f1c55cf47e
--- a/jdk/src/share/classes/java/lang/AbstractStringBuilder.java	Wed Jun 30 16:11:31 2010 -0700
+++ b/jdk/src/share/classes/java/lang/AbstractStringBuilder.java	Wed Jun 30 16:11:32 2010 -0700
@@ -721,20 +721,19 @@
      * {@code codePoint} isn't a valid Unicode code point
      */
     public AbstractStringBuilder appendCodePoint(int codePoint) {
-        if (!Character.isValidCodePoint(codePoint)) {
+        final int count = this.count;
+
+        if (Character.isBmpCodePoint(codePoint)) {
+            ensureCapacityInternal(count + 1);
+            value[count] = (char) codePoint;
+            this.count = count + 1;
+        } else if (Character.isValidCodePoint(codePoint)) {
+            ensureCapacityInternal(count + 2);
+            Character.toSurrogates(codePoint, value, count);
+            this.count = count + 2;
+        } else {
             throw new IllegalArgumentException();
         }
-        int n = 1;
-        if (codePoint >= Character.MIN_SUPPLEMENTARY_CODE_POINT) {
-            n++;
-        }
-        ensureCapacityInternal(count + n);
-        if (n == 1) {
-            value[count++] = (char) codePoint;
-        } else {
-            Character.toSurrogates(codePoint, value, count);
-            count += n;
-        }
         return this;
     }