From 4445e5e2ecc257a5d0fa2f2715bb7181a47346da Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 25 Sep 2012 12:26:12 -0400 Subject: [PATCH] [buffer] Cleanup / optimize UTF-16 parsing a bit --- src/hb-utf-private.hh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/hb-utf-private.hh b/src/hb-utf-private.hh index 2224a032d..f89aa23c1 100644 --- a/src/hb-utf-private.hh +++ b/src/hb-utf-private.hh @@ -86,14 +86,16 @@ hb_utf_next (const uint16_t *text, const uint16_t *end, hb_codepoint_t *unicode) { - uint16_t c = *text++; + hb_codepoint_t c = *text++; - if (unlikely (c >= 0xd800 && c < 0xdc00)) { + if (unlikely (hb_in_range (c, 0xd800, 0xdbff))) + { /* high surrogate */ - uint16_t l; - if (text < end && ((l = *text), likely (l >= 0xdc00 && l < 0xe000))) { + hb_codepoint_t l; + if (text < end && ((l = *text), likely (hb_in_range (l, 0xdc00, 0xdfff)))) + { /* low surrogate */ - *unicode = ((hb_codepoint_t) ((c) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000); + *unicode = (c << 10) + l - ((0xd800 << 10) - 0x10000 + 0xdc00); text++; } else *unicode = -1;