Bug 1960221 - Remove the aNeedsToCache parameter from nsLanguageAtomService::GetLanguageGroup, and simplify callers. r=emilio

We don't need this param; it should be safe to call the method from any thread
and just rely on its internal locking to protect the cache.

Differential Revision: https://phabricator.services.mozilla.com/D245357
This commit is contained in:
Jonathan Kew
2025-04-13 19:25:00 +00:00
parent 6bb4438d60
commit 41983aec3b
6 changed files with 37 additions and 89 deletions

View File

@@ -153,15 +153,12 @@ nsAtom* nsLanguageAtomService::GetLocaleLanguage() {
return mLocaleLanguage;
}
nsStaticAtom* nsLanguageAtomService::GetLanguageGroup(nsAtom* aLanguage,
bool* aNeedsToCache) {
if (aNeedsToCache) {
nsStaticAtom* nsLanguageAtomService::GetLanguageGroup(nsAtom* aLanguage) {
{
AutoReadLock lock(mLock);
if (nsStaticAtom* atom = mLangToGroup.Get(aLanguage)) {
return atom;
}
*aNeedsToCache = true;
return nullptr;
}
AutoWriteLock lock(mLock);

View File

@@ -36,26 +36,15 @@ class nsLanguageAtomService final {
already_AddRefed<nsAtom> LookupCharSet(NotNull<const Encoding*> aCharSet);
nsAtom* GetLocaleLanguage();
// Returns the language group that the specified language is a part of.
//
// aNeedsToCache is used for two things. If null, it indicates that
// the nsLanguageAtomService is safe to cache the result of the
// language group lookup, either because we're on the main thread,
// or because we're on a style worker thread but the font lock has
// been acquired. If non-null, it indicates that it's not safe to
// cache the result of the language group lookup (because we're on
// a style worker thread without the lock acquired). In this case,
// GetLanguageGroup will store true in *aNeedsToCache true if we
// would have cached the result of a new lookup, and false if we
// were able to use an existing cached result. Thus, callers that
// get a true *aNeedsToCache outparam value should make an effort
// to re-call GetLanguageGroup when it is safe to cache, to avoid
// recomputing the language group again later.
nsStaticAtom* GetLanguageGroup(nsAtom* aLanguage,
bool* aNeedsToCache = nullptr);
nsStaticAtom* GetUncachedLanguageGroup(nsAtom* aLanguage) const;
// Returns the language group that the specified language is a part of,
// using a cache to avoid repeatedly doing full lookups.
nsStaticAtom* GetLanguageGroup(nsAtom* aLanguage);
private:
// The core implementation of lang-tag to language-group lookup. (Now used
// only internally by GetLanguageGroup.)
nsStaticAtom* GetUncachedLanguageGroup(nsAtom* aLanguage) const;
static mozilla::StaticAutoPtr<nsLanguageAtomService> sLangAtomService;
nsTHashMap<RefPtr<nsAtom>, nsStaticAtom*> mLangToGroup MOZ_GUARDED_BY(mLock);