Commit e9f42cde authored by deanm@chromium.org's avatar deanm@chromium.org

Small cleanup to Utf8::CalculateValue:

  - Don't duplicate kMaxXByteChar constants.
  - Don't compare signed and unsigned integers.

Review URL: http://codereview.chromium.org/155414


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2434 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent d067f890
...@@ -194,18 +194,13 @@ static int LookupMapping(const int32_t* table, ...@@ -194,18 +194,13 @@ static int LookupMapping(const int32_t* table,
uchar Utf8::CalculateValue(const byte* str, uchar Utf8::CalculateValue(const byte* str,
unsigned length, unsigned length,
unsigned* cursor) { unsigned* cursor) {
static const uchar kMaxOneByteChar = 0x7F;
static const uchar kMaxTwoByteChar = 0x7FF;
static const uchar kMaxThreeByteChar = 0xFFFF;
static const uchar kMaxFourByteChar = 0x1FFFFF;
// We only get called for non-ascii characters. // We only get called for non-ascii characters.
if (length == 1) { if (length == 1) {
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
} }
int first = str[0]; byte first = str[0];
int second = str[1] ^ 0x80; byte second = str[1] ^ 0x80;
if (second & 0xC0) { if (second & 0xC0) {
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
...@@ -227,7 +222,7 @@ uchar Utf8::CalculateValue(const byte* str, ...@@ -227,7 +222,7 @@ uchar Utf8::CalculateValue(const byte* str,
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
} }
int third = str[2] ^ 0x80; byte third = str[2] ^ 0x80;
if (third & 0xC0) { if (third & 0xC0) {
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
...@@ -245,7 +240,7 @@ uchar Utf8::CalculateValue(const byte* str, ...@@ -245,7 +240,7 @@ uchar Utf8::CalculateValue(const byte* str,
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
} }
int fourth = str[3] ^ 0x80; byte fourth = str[3] ^ 0x80;
if (fourth & 0xC0) { if (fourth & 0xC0) {
*cursor += 1; *cursor += 1;
return kBadChar; return kBadChar;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment