Commit 32e001c6 authored by miloyip@gmail.com's avatar miloyip@gmail.com

Added Hoehrmann's UTF-8 decoder in perftest for reference

Minor optimization on UTF-8 validation

git-svn-id: https://rapidjson.googlecode.com/svn/trunk@37 c5894555-1306-4e8d-425f-1f6f381ee07c
parent 66754fc5
...@@ -372,21 +372,22 @@ struct UTF8 { ...@@ -372,21 +372,22 @@ struct UTF8 {
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8, 10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
}; };
#define COPY() os.Put(c = is.Take()) #define COPY() os.Put(c = is.Take())
#define TRANS(mask) if (!(type[(unsigned char)c] & mask)) return false #define TRANS(mask) result &= ((type[(unsigned char)c] & mask) != 0)
#define TAIL() COPY(); TRANS(0x70) #define TAIL() COPY(); TRANS(0x70)
Ch c; Ch c;
COPY(); COPY();
if (!(c & 0x80)) if (!(c & 0x80))
return true; return true;
bool result = true;
switch (type[(unsigned char)c]) { switch (type[(unsigned char)c]) {
case 2: TAIL(); return true; case 2: TAIL(); return result;
case 3: TAIL(); TAIL(); return true; case 3: TAIL(); TAIL(); return result;
case 4: COPY(); TRANS(0x50); TAIL(); return true; case 4: COPY(); TRANS(0x50); TAIL(); return result;
case 5: COPY(); TRANS(0x10); COPY(); TAIL(); return true; case 5: COPY(); TRANS(0x10); COPY(); TAIL(); return result;
case 6: TAIL(); TAIL(); TAIL(); return true; case 6: TAIL(); TAIL(); TAIL(); return result;
case 10: COPY(); TRANS(0x20); TAIL(); return true; case 10: COPY(); TRANS(0x20); TAIL(); return result;
case 11: COPY(); TRANS(0x60); TAIL(); return true; case 11: COPY(); TRANS(0x60); TAIL(); return result;
default: return false; default: return false;
} }
#undef COPY #undef COPY
......
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