[buffer] Cleanup / optimize UTF-16 parsing a bit
This commit is contained in:
parent
1f66c3c1a0
commit
4445e5e2ec
|
@ -86,14 +86,16 @@ hb_utf_next (const uint16_t *text,
|
||||||
const uint16_t *end,
|
const uint16_t *end,
|
||||||
hb_codepoint_t *unicode)
|
hb_codepoint_t *unicode)
|
||||||
{
|
{
|
||||||
uint16_t c = *text++;
|
hb_codepoint_t c = *text++;
|
||||||
|
|
||||||
if (unlikely (c >= 0xd800 && c < 0xdc00)) {
|
if (unlikely (hb_in_range<hb_codepoint_t> (c, 0xd800, 0xdbff)))
|
||||||
|
{
|
||||||
/* high surrogate */
|
/* high surrogate */
|
||||||
uint16_t l;
|
hb_codepoint_t l;
|
||||||
if (text < end && ((l = *text), likely (l >= 0xdc00 && l < 0xe000))) {
|
if (text < end && ((l = *text), likely (hb_in_range<hb_codepoint_t> (l, 0xdc00, 0xdfff))))
|
||||||
|
{
|
||||||
/* low surrogate */
|
/* low surrogate */
|
||||||
*unicode = ((hb_codepoint_t) ((c) - 0xd800) * 0x400 + (l) - 0xdc00 + 0x10000);
|
*unicode = (c << 10) + l - ((0xd800 << 10) - 0x10000 + 0xdc00);
|
||||||
text++;
|
text++;
|
||||||
} else
|
} else
|
||||||
*unicode = -1;
|
*unicode = -1;
|
||||||
|
|
Loading…
Reference in New Issue