Bug 1418156 - Move the PLDHashTable ops into PrefHashEntry. r=glandium
MozReview-Commit-ID: HJfjz2PzW0I
--- 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);