From 32e001c6846c112b12e57cad1315401001e53212 Mon Sep 17 00:00:00 2001 From: "miloyip@gmail.com" Date: Thu, 24 Nov 2011 08:00:22 +0000 Subject: [PATCH] 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 --- include/rapidjson/rapidjson.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/include/rapidjson/rapidjson.h b/include/rapidjson/rapidjson.h index bb4fd0c..19997e7 100644 --- a/include/rapidjson/rapidjson.h +++ b/include/rapidjson/rapidjson.h @@ -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, }; #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) Ch c; COPY(); if (!(c & 0x80)) return true; + bool result = true; switch (type[(unsigned char)c]) { - case 2: TAIL(); return true; - case 3: TAIL(); TAIL(); return true; - case 4: COPY(); TRANS(0x50); TAIL(); return true; - case 5: COPY(); TRANS(0x10); COPY(); TAIL(); return true; - case 6: TAIL(); TAIL(); TAIL(); return true; - case 10: COPY(); TRANS(0x20); TAIL(); return true; - case 11: COPY(); TRANS(0x60); TAIL(); return true; + case 2: TAIL(); return result; + case 3: TAIL(); TAIL(); return result; + case 4: COPY(); TRANS(0x50); TAIL(); return result; + case 5: COPY(); TRANS(0x10); COPY(); TAIL(); return result; + case 6: TAIL(); TAIL(); TAIL(); return result; + case 10: COPY(); TRANS(0x20); TAIL(); return result; + case 11: COPY(); TRANS(0x60); TAIL(); return result; default: return false; } #undef COPY