[ot-tags] Optimize subtag_matches() further

Part of https://github.com/harfbuzz/harfbuzz/issues/3591

Comparing before to after
Benchmark                                                               Time             CPU      Time Old      Time New       CPU Old       CPU New
----------------------------------------------------------------------------------------------------------------------------------------------------
BM_hb_ot_tags_from_script_and_language/COMMON abcd_XY                -0.3371         -0.3371            71            47            71            47
This commit is contained in:
Behdad Esfahbod 2022-05-17 16:58:35 -06:00
parent 27c11405a2
commit 7f6e8c5536
1 changed files with 4 additions and 0 deletions

View File

@ -195,6 +195,10 @@ subtag_matches (const char *lang_str,
const char *subtag)
{
unsigned subtag_len = strlen (subtag);
if (likely ((unsigned) (limit - lang_str) < subtag_len))
return false;
do {
const char *s = strstr (lang_str, subtag);
if (!s || s >= limit)