[ot-lang] Use atomic int for cache

Fixes(?) https://github.com/harfbuzz/harfbuzz/issues/3612
This commit is contained in:
Behdad Esfahbod 2022-05-26 18:24:43 -06:00
parent 67bd147c73
commit d61b207491
1 changed files with 3 additions and 3 deletions

View File

@ -297,13 +297,13 @@ hb_ot_tags_from_language (const char *lang_str,
hb_tag_t lang_tag = hb_tag_from_string (lang_str, first_len); hb_tag_t lang_tag = hb_tag_from_string (lang_str, first_len);
static unsigned last_tag_idx; /* Poor man's cache. */ static hb_atomic_int_t last_tag_idx; /* Poor man's cache. */
unsigned tag_idx = last_tag_idx; unsigned tag_idx = last_tag_idx.get_relaxed ();
if (likely (tag_idx < ot_languages_len && ot_languages[tag_idx].language == lang_tag) || if (likely (tag_idx < ot_languages_len && ot_languages[tag_idx].language == lang_tag) ||
hb_sorted_array (ot_languages, ot_languages_len).bfind (lang_tag, &tag_idx)) hb_sorted_array (ot_languages, ot_languages_len).bfind (lang_tag, &tag_idx))
{ {
last_tag_idx = tag_idx; last_tag_idx.set_relaxed (tag_idx);
unsigned int i; unsigned int i;
while (tag_idx != 0 && while (tag_idx != 0 &&
ot_languages[tag_idx].language == ot_languages[tag_idx - 1].language) ot_languages[tag_idx].language == ot_languages[tag_idx - 1].language)