Add hb_utf_strlen()

Speeds up UTF-8 parsing by calling strlen().
pull/1/head
Behdad Esfahbod 12 years ago
parent 7f19ae7b9f
commit 1f66c3c1a0
  1. 13
      src/hb-buffer.cc
  2. 22
      src/hb-utf-private.hh

@ -30,9 +30,6 @@
#include "hb-buffer-private.hh"
#include "hb-utf-private.hh"
#include <string.h>
#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;

@ -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 */

Loading…
Cancel
Save