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

Character.toCodePoint and Character.toSurrogates can be optimized

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 7
    • Fix Version/s: 7
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b68
    • CPU:
      generic
    • OS:
      generic

      Description

      The change below doesn't look like an optimization, but it is,
      because it enables compile-time constant folding.
      Each saves about 5 bytes of bytecode.


      --- /tmp/geta1287 2007-12-09 21:00:46.264231000 -0800
      +++ Character.java 2007-12-09 20:58:35.796806000 -0800
      @@ -2300,16 +2300,18 @@
            * @param high the high-surrogate code unit
            * @param low the low-surrogate code unit
            * @return the supplementary code point composed from the
            * specified surrogate pair.
            * @since 1.5
            */
           public static int toCodePoint(char high, char low) {
      - return ((high - MIN_HIGH_SURROGATE) << 10)
      - + (low - MIN_LOW_SURROGATE) + MIN_SUPPLEMENTARY_CODE_POINT;
      + return ((high << 10) + low)
      + + (MIN_SUPPLEMENTARY_CODE_POINT
      + - (MIN_HIGH_SURROGATE << 10)
      + - MIN_LOW_SURROGATE);
           }
       
           /**
            * Returns the code point at the given index of the
            * <code>CharSequence</code>. If the <code>char</code> value at
            * the given index in the <code>CharSequence</code> is in the
            * high-surrogate range, the following index is less than the
      @@ -2587,17 +2589,19 @@
               }
               char[] result = new char[2];
               toSurrogates(codePoint, result, 0);
               return result;
           }
       
           static void toSurrogates(int codePoint, char[] dst, int index) {
      - int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT;
      - dst[index+1] = (char)((offset & 0x3ff) + MIN_LOW_SURROGATE);
      - dst[index] = (char)((offset >>> 10) + MIN_HIGH_SURROGATE);
      + dst[index] = (char)
      + ((codePoint >>> 10)
      + + (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >> 10)));
      + dst[index+1] = (char)
      + ((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
           }
       
           /**
            * Returns the number of Unicode code points in the text range of
            * the specified char sequence. The text range begins at the
            * specified <code>beginIndex</code> and extends to the
            * <code>char</code> at index <code>endIndex - 1</code>. Thus the

        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: