Tom Tromey wrote:
> Chris> Please comment.
> 
> Chris> -        dst[dstIndex + 1] = (char) ((codePoint & 0x3ff)
> Chris> -                                    + (int) MIN_LOW_SURROGATE );
> Chris> -        dst[dstIndex] = (char) ((codePoint >> 10) + (int) 
> MIN_HIGH_SURROGATE);
> Chris> +        dst[dstIndex + 1] = (char) (((codePoint - 0x10000) % 0x400) + 
> 0xdc00);
> Chris> +        dst[dstIndex] = (char) (((codePoint - 0x10000) / 0x400) + 
> 0xd800);
> 
> I think it is better to use the named constants instead of the values.

Fair enough, but what about the casting: doesn't that make it less efficient?
Actually I should only be doing the subtraction once here on that basis.

> I also have a mild preference for the bit-shifting and masking
> computation, but this is more minor.

The problem is that the bit-shifting method produces the wrong result.

What about the version attached here, is that better?
-- 
Chris Burdess
  "They that can give up essential liberty to obtain a little safety
  deserve neither liberty nor safety." - Benjamin Franklin
Index: java/lang/Character.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Character.java,v
retrieving revision 1.40
diff -u -r1.40 Character.java
--- java/lang/Character.java    17 Sep 2005 21:58:41 -0000      1.40
+++ java/lang/Character.java    8 Jan 2006 08:52:41 -0000
@@ -2410,11 +2410,11 @@
       {
         // Write second char first to cause IndexOutOfBoundsException
         // immediately.
-        dst[dstIndex + 1] = (char) ((codePoint & 0x3ff)
-                                    + (int) MIN_LOW_SURROGATE );
-        dst[dstIndex] = (char) ((codePoint >> 10) + (int) MIN_HIGH_SURROGATE);
+        final int cp2 = codePoint - 0x10000;
+        dst[dstIndex + 1] = (char) ((cp2 % 0x400) + (int) MIN_LOW_SURROGATE);
+        dst[dstIndex] = (char) ((cp2 / 0x400) + (int) MIN_HIGH_SURROGATE);
         result = 2;
-    }
+      }
     else
       {
         dst[dstIndex] = (char) codePoint;

Attachment: pgpWxWb1o10Ue.pgp
Description: PGP signature

_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to