From 87a12bf482b6f012e0c895633deb511966bb7069 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 13 Jul 2015 19:08:31 -0700 Subject: [PATCH] Bug 1182962 (part 3) - Use nsTHashtable::Iterator in gfxPlatformFontList. r=jdaggett. --- gfx/thebes/gfxPlatformFontList.cpp | 90 ++++++++---------------------- gfx/thebes/gfxPlatformFontList.h | 8 +-- 2 files changed, 25 insertions(+), 73 deletions(-) diff --git a/gfx/thebes/gfxPlatformFontList.cpp b/gfx/thebes/gfxPlatformFontList.cpp index 4c0ed0f15b9..f326d821149 100644 --- a/gfx/thebes/gfxPlatformFontList.cpp +++ b/gfx/thebes/gfxPlatformFontList.cpp @@ -436,19 +436,11 @@ gfxPlatformFontList::LoadBadUnderlineList() } } -static PLDHashOperator -RebuildLocalFonts(nsPtrHashKey* aKey, - void* aClosure) -{ - aKey->GetKey()->RebuildLocalRules(); - return PL_DHASH_NEXT; -} - void gfxPlatformFontList::UpdateFontList() { InitFontList(); - mUserFontSetList.EnumerateEntries(RebuildLocalFonts, nullptr); + RebuildLocalFonts(); } struct FontListData { @@ -966,50 +958,6 @@ gfxPlatformFontList::LoadFontInfo() return done; } -struct LookupMissedFaceNamesData { - explicit LookupMissedFaceNamesData(gfxPlatformFontList *aFontList) - : mFontList(aFontList), mFoundName(false) {} - - gfxPlatformFontList *mFontList; - bool mFoundName; -}; - -/*static*/ PLDHashOperator -gfxPlatformFontList::LookupMissedFaceNamesProc(nsStringHashKey *aKey, - void *aUserArg) -{ - LookupMissedFaceNamesData *data = - reinterpret_cast(aUserArg); - - if (data->mFontList->FindFaceName(aKey->GetKey())) { - data->mFoundName = true; - return PL_DHASH_STOP; - } - return PL_DHASH_NEXT; -} - -struct LookupMissedOtherNamesData { - explicit LookupMissedOtherNamesData(gfxPlatformFontList *aFontList) - : mFontList(aFontList), mFoundName(false) {} - - gfxPlatformFontList *mFontList; - bool mFoundName; -}; - -/*static*/ PLDHashOperator -gfxPlatformFontList::LookupMissedOtherNamesProc(nsStringHashKey *aKey, - void *aUserArg) -{ - LookupMissedOtherNamesData *data = - reinterpret_cast(aUserArg); - - if (data->mFontList->FindFamily(aKey->GetKey())) { - data->mFoundName = true; - return PL_DHASH_STOP; - } - return PL_DHASH_NEXT; -} - void gfxPlatformFontList::CleanupLoader() { @@ -1018,26 +966,26 @@ gfxPlatformFontList::CleanupLoader() bool rebuilt = false, forceReflow = false; // if had missed face names that are now available, force reflow all - if (mFaceNamesMissed && - mFaceNamesMissed->Count() != 0) { - LookupMissedFaceNamesData namedata(this); - mFaceNamesMissed->EnumerateEntries(LookupMissedFaceNamesProc, &namedata); - if (namedata.mFoundName) { - rebuilt = true; - mUserFontSetList.EnumerateEntries(RebuildLocalFonts, nullptr); + if (mFaceNamesMissed) { + for (auto it = mFaceNamesMissed->Iter(); !it.Done(); it.Next()) { + if (FindFaceName(it.Get()->GetKey())) { + rebuilt = true; + RebuildLocalFonts(); + break; + } } mFaceNamesMissed = nullptr; } if (mOtherNamesMissed) { - LookupMissedOtherNamesData othernamesdata(this); - mOtherNamesMissed->EnumerateEntries(LookupMissedOtherNamesProc, - &othernamesdata); - mOtherNamesMissed = nullptr; - if (othernamesdata.mFoundName) { - forceReflow = true; - ForceGlobalReflow(); + for (auto it = mOtherNamesMissed->Iter(); !it.Done(); it.Next()) { + if (FindFamily(it.Get()->GetKey())) { + forceReflow = true; + ForceGlobalReflow(); + break; + } } + mOtherNamesMissed = nullptr; } if (LOG_FONTINIT_ENABLED() && mFontInfo) { @@ -1080,6 +1028,14 @@ gfxPlatformFontList::ForceGlobalReflow() Preferences::SetBool(kPrefName, !fontInternalChange); } +void +gfxPlatformFontList::RebuildLocalFonts() +{ + for (auto it = mUserFontSetList.Iter(); !it.Done(); it.Next()) { + it.Get()->GetKey()->RebuildLocalRules(); + } +} + // Support for memory reporting static size_t diff --git a/gfx/thebes/gfxPlatformFontList.h b/gfx/thebes/gfxPlatformFontList.h index 7eacb332066..a4bc825182b 100644 --- a/gfx/thebes/gfxPlatformFontList.h +++ b/gfx/thebes/gfxPlatformFontList.h @@ -268,12 +268,6 @@ protected: // maintains explicit mappings of fullname/psname ==> font virtual gfxFontEntry* LookupInFaceNameLists(const nsAString& aFontName); - static PLDHashOperator LookupMissedFaceNamesProc(nsStringHashKey *aKey, - void *aUserArg); - - static PLDHashOperator LookupMissedOtherNamesProc(nsStringHashKey *aKey, - void *aUserArg); - // commonly used fonts for which the name table should be loaded at startup virtual void PreloadNamesList(); @@ -300,6 +294,8 @@ protected: // for font list changes that affect all documents void ForceGlobalReflow(); + void RebuildLocalFonts(); + // used by memory reporter to accumulate sizes of family names in the hash static size_t SizeOfFamilyNameEntryExcludingThis(const nsAString& aKey,