mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-06 06:00:26 +00:00
6639443: Character.toCodePoint and Character.toSurrogates can be optimized
Rearranging code saves 5 bytes of bytecode Reviewed-by: sherman
This commit is contained in:
parent
3bb5216024
commit
7ac7d3079f
@ -2784,8 +2784,13 @@ class Character extends Object implements java.io.Serializable, Comparable<Chara
|
||||
* @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;
|
||||
// Optimized form of:
|
||||
// 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
|
||||
}
|
||||
|
||||
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);
|
||||
// We write elements "backwards" to guarantee all-or-nothing
|
||||
dst[index+1] = (char)((codePoint & 0x3ff) + MIN_LOW_SURROGATE);
|
||||
dst[index] = (char)((codePoint >>> 10)
|
||||
+ (MIN_HIGH_SURROGATE - (MIN_SUPPLEMENTARY_CODE_POINT >>> 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user