mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 22:41:10 +01:00
Merge pull request #6607 from harfbuzz/fix/revert-language-cache
Revert "[common] Cache the last hb_language_from_string() result"
This commit is contained in:
1 parent
a40bb748d1
commit
539a034cf2
1 file changed
-17
@@ -237,17 +237,10 @@ struct hb_language_item_t {
|
||||
/* Thread-safe lockfree language list */
|
||||
|
||||
static hb_atomic_t<hb_language_item_t *> langs;
|
||||
/* One-entry cache of the most recently returned language, so that repeated
|
||||
* lookups of the same tag (the common case: every run of a mostly-one-language
|
||||
* document) return without walking the whole list. Interned languages are
|
||||
* never freed, so a cached pointer stays valid; a stale or raced read just
|
||||
* falls through to the list scan below. */
|
||||
static hb_atomic_t<hb_language_item_t *> last_found_lang;
|
||||
|
||||
static inline void
|
||||
free_langs ()
|
||||
{
|
||||
last_found_lang.set_relaxed (nullptr);
|
||||
retry:
|
||||
hb_language_item_t *first_lang = langs;
|
||||
if (unlikely (!langs.cmpexch (first_lang, nullptr)))
|
||||
@@ -264,21 +257,12 @@ retry:
|
||||
static hb_language_item_t *
|
||||
lang_find_or_insert (const char *key)
|
||||
{
|
||||
/* Fast path: the most recently returned language. Repeated lookups of the
|
||||
* same tag hit here without walking the list. */
|
||||
hb_language_item_t *cached = last_found_lang.get_acquire ();
|
||||
if (cached && *cached == key)
|
||||
return cached;
|
||||
|
||||
retry:
|
||||
hb_language_item_t *first_lang = langs;
|
||||
|
||||
for (hb_language_item_t *lang = first_lang; lang; lang = lang->next)
|
||||
if (*lang == key)
|
||||
{
|
||||
last_found_lang.set_release (lang);
|
||||
return lang;
|
||||
}
|
||||
|
||||
/* Not found; allocate one. */
|
||||
hb_language_item_t *lang = (hb_language_item_t *) hb_calloc (1, sizeof (hb_language_item_t));
|
||||
@@ -302,7 +286,6 @@ retry:
|
||||
if (!first_lang)
|
||||
hb_atexit (free_langs); /* First person registers atexit() callback. */
|
||||
|
||||
last_found_lang.set_release (lang);
|
||||
return lang;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user