Bug 1170069 - Use PLDHashTable2 in FontNameCache. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 31 May 2015 22:14:44 -0700
changeset 246866 8f567d651c1a281408fa7a92767ac5a7ea11cd2f
parent 246865 b38c7d19b1d63a084ba487487fba26c0e963f362
child 246867 739e16f56c9035f978591c8410b461ed21baa6f7
push id28843
push usercbook@mozilla.com
push dateWed, 03 Jun 2015 11:50:02 +0000
treeherdermozilla-central@6c612d7adbf5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1170069
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1170069 - Use PLDHashTable2 in FontNameCache. r=froydnj.
gfx/thebes/gfxFT2FontList.cpp
--- a/gfx/thebes/gfxFT2FontList.cpp
+++ b/gfx/thebes/gfxFT2FontList.cpp
@@ -612,49 +612,50 @@ FT2FontFamily::AddFacesToFontList(Infall
  * find their attributes), leading to significantly quicker startup.
  */
 
 #define CACHE_KEY "font.cached-list"
 
 class FontNameCache {
 public:
     FontNameCache()
-        : mWriteNeeded(false)
+        : mMap(&mOps, sizeof(FNCMapEntry), 0)
+        , mWriteNeeded(false)
     {
+        // HACK ALERT: it's weird to assign |mOps| after we passed a pointer to
+        // it to |mMap|'s constructor. A more normal approach here would be to
+        // have a static |sOps| member. Unfortunately, this mysteriously but
+        // consistently makes Fennec start-up slower, so we take this
+        // unorthodox approach instead. It's safe because PLDHashTable's
+        // constructor doesn't dereference the pointer; it just makes a copy of
+        // it.
         mOps = (PLDHashTableOps) {
             StringHash,
             HashMatchEntry,
             MoveEntry,
             PL_DHashClearEntryStub,
             nullptr
         };
 
-        PL_DHashTableInit(&mMap, &mOps, sizeof(FNCMapEntry), 0);
-
         MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default,
                    "StartupCacheFontNameCache should only be used in chrome "
                    "process");
         mCache = mozilla::scache::StartupCache::GetSingleton();
 
         Init();
     }
 
     ~FontNameCache()
     {
-        if (!mMap.IsInitialized()) {
-            return;
-        }
         if (!mWriteNeeded || !mCache) {
-            PL_DHashTableFinish(&mMap);
             return;
         }
 
         nsAutoCString buf;
         PL_DHashTableEnumerate(&mMap, WriteOutMap, &buf);
-        PL_DHashTableFinish(&mMap);
         mCache->PutBuffer(CACHE_KEY, buf.get(), buf.Length() + 1);
     }
 
     void Init()
     {
         if (!mMap.IsInitialized() || !mCache) {
             return;
         }
@@ -743,17 +744,17 @@ public:
             entry->mFaces.Assign(aFaceList);
             entry->mFileExists = true;
         }
         mWriteNeeded = true;
     }
 
 private:
     mozilla::scache::StartupCache* mCache;
-    PLDHashTable mMap;
+    PLDHashTable2 mMap;
     bool mWriteNeeded;
 
     PLDHashTableOps mOps;
 
     static PLDHashOperator WriteOutMap(PLDHashTable *aTable,
                                        PLDHashEntryHdr *aHdr,
                                        uint32_t aNumber, void *aData)
     {