Bug 1418156 - Move the PLDHashTable ops into PrefHashEntry. r=glandium draft
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 17 Nov 2017 12:16:31 +1100
changeset 699339 2fa444bacf2bcd7c941751ad0e9bb4a0f09bdd83
parent 699338 58e954057ce93e3a71a8ea7d72e9a59a6346c6f2
child 699340 b3d483a9aba327cf3aba61979a5198c80c63a0c9
push id89536
push usernnethercote@mozilla.com
push dateFri, 17 Nov 2017 01:25:26 +0000
reviewersglandium
bugs1418156
milestone59.0a1
Bug 1418156 - Move the PLDHashTable ops into PrefHashEntry. r=glandium MozReview-Commit-ID: HJfjz2PzW0I
modules/libpref/Preferences.cpp
--- a/modules/libpref/Preferences.cpp
+++ b/modules/libpref/Preferences.cpp
@@ -184,16 +184,47 @@ public:
   bool HasDefaultValue() const { return mHasDefaultValue; }
   void SetHasDefaultValue(bool aValue) { mHasDefaultValue = aValue; }
 
   bool HasUserValue() const { return mHasUserValue; }
   void SetHasUserValue(bool aValue) { mHasUserValue = aValue; }
 
   // Other operations.
 
+  static bool MatchEntry(const PLDHashEntryHdr* aEntry, const void* aKey)
+  {
+    auto pref = static_cast<const PrefHashEntry*>(aEntry);
+
+    if (pref->mKey == aKey) {
+      return true;
+    }
+
+    if (!pref->mKey || !aKey) {
+      return false;
+    }
+
+    auto otherKey = static_cast<const char*>(aKey);
+    return (strcmp(pref->mKey, otherKey) == 0);
+  }
+
+  static void ClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
+  {
+    auto pref = static_cast<PrefHashEntry*>(aEntry);
+
+    if (pref->IsTypeString()) {
+      free(const_cast<char*>(pref->mDefaultValue.mStringVal));
+      free(const_cast<char*>(pref->mUserValue.mStringVal));
+    }
+
+    // Don't need to free this because it's allocated in memory owned by
+    // gPrefNameArena.
+    pref->mKey = nullptr;
+    memset(aEntry, 0, aTable->EntrySize());
+  }
+
   size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf)
   {
     // Note: mKey is allocated in gPrefNameArena, measured elsewhere.
     size_t n = 0;
     if (IsTypeString()) {
       if (HasDefaultValue()) {
         n += aMallocSizeOf(mDefaultValue.mStringVal);
       }
@@ -215,48 +246,16 @@ private:
   uint32_t mHasDefaultValue : 1;
 
 public:
   const char* mKey;
   PrefValue mDefaultValue;
   PrefValue mUserValue;
 };
 
-static void
-ClearPrefEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry)
-{
-  auto pref = static_cast<PrefHashEntry*>(aEntry);
-  if (pref->IsTypeString()) {
-    free(const_cast<char*>(pref->mDefaultValue.mStringVal));
-    free(const_cast<char*>(pref->mUserValue.mStringVal));
-  }
-
-  // Don't need to free this because it's allocated in memory owned by
-  // gPrefNameArena.
-  pref->mKey = nullptr;
-  memset(aEntry, 0, aTable->EntrySize());
-}
-
-static bool
-MatchPrefEntry(const PLDHashEntryHdr* aEntry, const void* aKey)
-{
-  auto pref = static_cast<const PrefHashEntry*>(aEntry);
-
-  if (pref->mKey == aKey) {
-    return true;
-  }
-
-  if (!pref->mKey || !aKey) {
-    return false;
-  }
-
-  auto otherKey = static_cast<const char*>(aKey);
-  return (strcmp(pref->mKey, otherKey) == 0);
-}
-
 struct CallbackNode
 {
   const char* mDomain;
 
   // If someone attempts to remove the node from the callback list while
   // pref_DoCallback is running, |func| is set to nullptr. Such nodes will
   // be removed at the end of pref_DoCallback.
   PrefChangedFunc mFunc;
@@ -277,19 +276,19 @@ static CallbackNode* gLastPriorityNode =
 static bool gIsAnyPrefLocked = false;
 
 // These are only used during the call to pref_DoCallback.
 static bool gCallbacksInProgress = false;
 static bool gShouldCleanupDeadNodes = false;
 
 static PLDHashTableOps pref_HashTableOps = {
   PLDHashTable::HashStringKey,
-  MatchPrefEntry,
+  PrefHashEntry::MatchEntry,
   PLDHashTable::MoveEntryStub,
-  ClearPrefEntry,
+  PrefHashEntry::ClearEntry,
   nullptr,
 };
 
 //---------------------------------------------------------------------------
 
 static PrefHashEntry*
 pref_HashTableLookup(const char* aKey);