From 1f66c3c1a0eb869c0d85a015235313177e0cec62 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 25 Sep 2012 11:42:16 -0400 Subject: [PATCH] Add hb_utf_strlen() Speeds up UTF-8 parsing by calling strlen(). --- src/hb-buffer.cc | 13 ++----------- src/hb-utf-private.hh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/hb-buffer.cc b/src/hb-buffer.cc index f84511d17..6da196fe3 100644 --- a/src/hb-buffer.cc +++ b/src/hb-buffer.cc @@ -30,9 +30,6 @@ #include "hb-buffer-private.hh" #include "hb-utf-private.hh" -#include - - #ifndef HB_DEBUG_BUFFER #define HB_DEBUG_BUFFER (HB_DEBUG+0) @@ -812,14 +809,8 @@ hb_buffer_add_utf (hb_buffer_t *buffer, if (unlikely (hb_object_is_inert (buffer))) return; - if (text_length == -1) { - text_length = 0; - const T *p = (const T *) text; - while (*p) { - text_length++; - p++; - } - } + if (text_length == -1) + text_length = hb_utf_strlen (text); if (item_length == -1) item_length = text_length - item_offset; diff --git a/src/hb-utf-private.hh b/src/hb-utf-private.hh index 829ca5045..2224a032d 100644 --- a/src/hb-utf-private.hh +++ b/src/hb-utf-private.hh @@ -72,6 +72,12 @@ hb_utf_next (const uint8_t *text, } } +static inline unsigned int +hb_utf_strlen (const uint8_t *text) +{ + return strlen ((const char *) text); +} + /* UTF-16 */ @@ -97,6 +103,14 @@ hb_utf_next (const uint16_t *text, return text; } +static inline unsigned int +hb_utf_strlen (const uint16_t *text) +{ + unsigned int l = 0; + while (*text++) l++; + return l; +} + /* UTF-32 */ @@ -109,5 +123,13 @@ hb_utf_next (const uint32_t *text, return text + 1; } +static inline unsigned int +hb_utf_strlen (const uint32_t *text) +{ + unsigned int l = 0; + while (*text++) l++; + return l; +} + #endif /* HB_UTF_PRIVATE_HH */