Micro-optimize hb_language_from_string()
As measured / improved by Benson Limketkai.
This commit is contained in:
parent
f2ad935e19
commit
f3159ba514
|
@ -293,21 +293,21 @@ retry:
|
||||||
hb_language_t
|
hb_language_t
|
||||||
hb_language_from_string (const char *str, int len)
|
hb_language_from_string (const char *str, int len)
|
||||||
{
|
{
|
||||||
char strbuf[64];
|
|
||||||
|
|
||||||
if (!str || !len || !*str)
|
if (!str || !len || !*str)
|
||||||
return HB_LANGUAGE_INVALID;
|
return HB_LANGUAGE_INVALID;
|
||||||
|
|
||||||
|
hb_language_item_t *item = NULL;
|
||||||
if (len >= 0)
|
if (len >= 0)
|
||||||
{
|
{
|
||||||
/* NUL-terminate it. */
|
/* NUL-terminate it. */
|
||||||
|
char strbuf[64];
|
||||||
len = MIN (len, (int) sizeof (strbuf) - 1);
|
len = MIN (len, (int) sizeof (strbuf) - 1);
|
||||||
memcpy (strbuf, str, len);
|
memcpy (strbuf, str, len);
|
||||||
strbuf[len] = '\0';
|
strbuf[len] = '\0';
|
||||||
str = strbuf;
|
item = lang_find_or_insert (strbuf);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
hb_language_item_t *item = lang_find_or_insert (str);
|
item = lang_find_or_insert (str);
|
||||||
|
|
||||||
return likely (item) ? item->lang : HB_LANGUAGE_INVALID;
|
return likely (item) ? item->lang : HB_LANGUAGE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue