6931812: A better implementation of sun.nio.cs.Surrogate.isBMP(int)
authormartin
Wed, 10 Mar 2010 14:53:51 -0800
changeset 5144 9fab813ff16c
parent 5143 a1682a41e70f
child 5145 da75dc06a7f5
6931812: A better implementation of sun.nio.cs.Surrogate.isBMP(int) Summary: uc >> 16 == 0 is superior to (int) (char) uc == uc Reviewed-by: sherman Contributed-by: Ulf Zibis <ulf.zibis@gmx.de>
jdk/src/share/classes/sun/nio/cs/Surrogate.java
--- a/jdk/src/share/classes/sun/nio/cs/Surrogate.java	Wed Mar 10 14:44:53 2010 +0000
+++ b/jdk/src/share/classes/sun/nio/cs/Surrogate.java	Wed Mar 10 14:53:51 2010 -0800
@@ -78,8 +78,8 @@
      * Tells whether or not the given UCS-4 character is in the Basic
      * Multilingual Plane, and can be represented using a single char.
      */
-    public static boolean isBMP(int uc) {
-        return (int) (char) uc == uc;
+    public static boolean isBMPCodePoint(int uc) {
+        return uc >> 16 == 0;
     }
 
     /**
@@ -290,7 +290,7 @@
          *           error() will return a descriptive result object
          */
         public int generate(int uc, int len, CharBuffer dst) {
-            if (Surrogate.isBMP(uc)) {
+            if (Surrogate.isBMPCodePoint(uc)) {
                 if (Surrogate.is(uc)) {
                     error = CoderResult.malformedForLength(len);
                     return -1;
@@ -334,7 +334,7 @@
          *           error() will return a descriptive result object
          */
         public int generate(int uc, int len, char[] da, int dp, int dl) {
-            if (Surrogate.isBMP(uc)) {
+            if (Surrogate.isBMPCodePoint(uc)) {
                 if (Surrogate.is(uc)) {
                     error = CoderResult.malformedForLength(len);
                     return -1;