提交 621f22a7 编写于 作者: M martin

6639443: Character.toCodePoint and Character.toSurrogates can be optimized

Summary: rearranging code saves 5 bytes of bytecode
Reviewed-by: sherman
上级 d9daa38a
...@@ -2784,8 +2784,13 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara ...@@ -2784,8 +2784,13 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara
* @since 1.5 * @since 1.5
*/ */
public static int toCodePoint(char high, char low) { public static int toCodePoint(char high, char low) {
return ((high - MIN_HIGH_SURROGATE) << 10) // Optimized form of:
+ (low - MIN_LOW_SURROGATE) + MIN_SUPPLEMENTARY_CODE_POINT; // 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);
} }
/** /**
...@@ -3071,9 +3076,10 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara ...@@ -3071,9 +3076,10 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara
} }
static void toSurrogates(int codePoint, char[] dst, int index) { static void toSurrogates(int codePoint, char[] dst, int index) {
int offset = codePoint - MIN_SUPPLEMENTARY_CODE_POINT; // We write elements "backwards" to guarantee all-or-nothing
dst[index+1] = (char)((offset & 0x3ff) + MIN_LOW_SURROGATE); dst[index+1] = (char)((codePoint & 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)));
} }
/** /**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册