Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6639458

Improvements to Surrogate.java

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:

      Description

      The methods high, low and toUCS4 can be optimized, as in
      6639443: Character.toCodePoint and Character.toSurrogates can be optimized

      In the generate methods, the test
      uc <= 0xffff
      and
      uc < Surrogate.UCS4_MIN

      are identical, so the latter code can be deleted.

      --- /u/martin/ws/dolphin/src/share/classes/sun/nio/cs/Surrogate.java 2007-05-13 03:03:30.484210000 -0700
      +++ /u/martin/ws/concurrent/src/share/classes/sun/nio/cs/Surrogate.java 2007-12-09 20:50:41.580695000 -0800
      @@ -90,7 +90,7 @@
            */
           public static char high(int uc) {
        assert neededFor(uc);
      - return (char)(0xd800 | (((uc - UCS4_MIN) >> 10) & 0x3ff));
      + return (char)((uc >> 10) + (MIN_HIGH - (UCS4_MIN >> 10)));
           }
       
           /**
      @@ -98,15 +98,14 @@
            */
           public static char low(int uc) {
        assert neededFor(uc);
      - return (char)(0xdc00 | ((uc - UCS4_MIN) & 0x3ff));
      + return (char)((uc & 0x3ff) + MIN_LOW);
           }
       
           /**
            * Converts the given surrogate pair into a 32-bit UCS-4 character.
            */
           public static int toUCS4(char c, char d) {
      - assert isHigh(c) && isLow(d);
      - return (((c & 0x3ff) << 10) | (d & 0x3ff)) + 0x10000;
      + return Character.toCodePoint(c, d);
           }
       
           /**
      @@ -179,14 +178,14 @@
        * object
        */
        public int parse(char c, CharBuffer in) {
      - if (Surrogate.isHigh(c)) {
      + if (Character.isHighSurrogate(c)) {
        if (!in.hasRemaining()) {
        error = CoderResult.UNDERFLOW;
        return -1;
        }
        char d = in.get();
      - if (Surrogate.isLow(d)) {
      - character = toUCS4(c, d);
      + if (Character.isLowSurrogate(d)) {
      + character = Character.toCodePoint(c, d);
        isPair = true;
        error = null;
        return character;
      @@ -194,7 +193,7 @@
        error = CoderResult.malformedForLength(1);
        return -1;
        }
      - if (Surrogate.isLow(c)) {
      + if (Character.isLowSurrogate(c)) {
        error = CoderResult.malformedForLength(1);
        return -1;
        }
      @@ -221,14 +220,14 @@
        */
        public int parse(char c, char[] ia, int ip, int il) {
        assert (ia[ip] == c);
      - if (Surrogate.isHigh(c)) {
      + if (Character.isHighSurrogate(c)) {
        if (il - ip < 2) {
        error = CoderResult.UNDERFLOW;
        return -1;
        }
        char d = ia[ip + 1];
      - if (Surrogate.isLow(d)) {
      - character = toUCS4(c, d);
      + if (Character.isLowSurrogate(d)) {
      + character = Character.toCodePoint(c, d);
        isPair = true;
        error = null;
        return character;
      @@ -236,7 +235,7 @@
        error = CoderResult.malformedForLength(1);
        return -1;
        }
      - if (Surrogate.isLow(c)) {
      + if (Character.isLowSurrogate(c)) {
        error = CoderResult.malformedForLength(1);
        return -1;
        }
      @@ -296,10 +295,6 @@
        error = null;
        return 1;
        }
      - if (uc < Surrogate.UCS4_MIN) {
      - error = CoderResult.malformedForLength(len);
      - return -1;
      - }
        if (uc <= Surrogate.UCS4_MAX) {
        if (dst.remaining() < 2) {
        error = CoderResult.OVERFLOW;
      @@ -331,7 +326,7 @@
        * error() will return a descriptive result object
        */
        public int generate(int uc, int len, char[] da, int dp, int dl) {
      - if (uc <= 0xffff) {
      + if (uc < Surrogate.UCS4_MIN) {
        if (Surrogate.is(uc)) {
        error = CoderResult.malformedForLength(len);
        return -1;
      @@ -344,10 +339,6 @@
        error = null;
        return 1;
        }
      - if (uc < Surrogate.UCS4_MIN) {
      - error = CoderResult.malformedForLength(len);
      - return -1;
      - }
        if (uc <= Surrogate.UCS4_MAX) {
        if (dl - dp < 2) {
        error = CoderResult.OVERFLOW;

        Attachments

          Activity

            People

            • Assignee:
              sherman Xueming Shen
              Reporter:
              martin Martin Buchholz
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: