提交 43f3efde 编写于 作者: M martin

6931812: A better implementation of sun.nio.cs.Surrogate.isBMP(int)

Summary: uc >> 16 == 0 is superior to (int) (char) uc == uc
Reviewed-by: sherman
Contributed-by: NUlf Zibis <ulf.zibis@gmx.de>
上级 3ff03ce6
...@@ -78,8 +78,8 @@ public class Surrogate { ...@@ -78,8 +78,8 @@ public class Surrogate {
* Tells whether or not the given UCS-4 character is in the Basic * Tells whether or not the given UCS-4 character is in the Basic
* Multilingual Plane, and can be represented using a single char. * Multilingual Plane, and can be represented using a single char.
*/ */
public static boolean isBMP(int uc) { public static boolean isBMPCodePoint(int uc) {
return (int) (char) uc == uc; return uc >> 16 == 0;
} }
/** /**
...@@ -290,7 +290,7 @@ public class Surrogate { ...@@ -290,7 +290,7 @@ public class Surrogate {
* error() will return a descriptive result object * error() will return a descriptive result object
*/ */
public int generate(int uc, int len, CharBuffer dst) { public int generate(int uc, int len, CharBuffer dst) {
if (Surrogate.isBMP(uc)) { if (Surrogate.isBMPCodePoint(uc)) {
if (Surrogate.is(uc)) { if (Surrogate.is(uc)) {
error = CoderResult.malformedForLength(len); error = CoderResult.malformedForLength(len);
return -1; return -1;
...@@ -334,7 +334,7 @@ public class Surrogate { ...@@ -334,7 +334,7 @@ public class Surrogate {
* error() will return a descriptive result object * error() will return a descriptive result object
*/ */
public int generate(int uc, int len, char[] da, int dp, int dl) { public int generate(int uc, int len, char[] da, int dp, int dl) {
if (Surrogate.isBMP(uc)) { if (Surrogate.isBMPCodePoint(uc)) {
if (Surrogate.is(uc)) { if (Surrogate.is(uc)) {
error = CoderResult.malformedForLength(len); error = CoderResult.malformedForLength(len);
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册