From e7c913bc12e69f29e29aca55daa74bb853b9bd8e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Nov 2017 15:29:29 +1100 Subject: [PATCH] Bug 1418156 - Move the PLDHashTable ops into PrefHashEntry. r=glandium MozReview-Commit-ID: HJfjz2PzW0I --HG-- extra : rebase_source : 717a3d5121a33ca01da5c0b5298386f4c8345eae --- modules/libpref/Preferences.cpp | 67 ++++++++++++++++----------------- 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index e5d8c1845b59..18c61c842124 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -189,6 +189,37 @@ public: // Other operations. + static bool MatchEntry(const PLDHashEntryHdr* aEntry, const void* aKey) + { + auto pref = static_cast(aEntry); + + if (pref->mKey == aKey) { + return true; + } + + if (!pref->mKey || !aKey) { + return false; + } + + auto otherKey = static_cast(aKey); + return (strcmp(pref->mKey, otherKey) == 0); + } + + static void ClearEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry) + { + auto pref = static_cast(aEntry); + + if (pref->IsTypeString()) { + free(const_cast(pref->mDefaultValue.mStringVal)); + free(const_cast(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. @@ -220,38 +251,6 @@ public: PrefValue mUserValue; }; -static void -ClearPrefEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry) -{ - auto pref = static_cast(aEntry); - if (pref->IsTypeString()) { - free(const_cast(pref->mDefaultValue.mStringVal)); - free(const_cast(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(aEntry); - - if (pref->mKey == aKey) { - return true; - } - - if (!pref->mKey || !aKey) { - return false; - } - - auto otherKey = static_cast(aKey); - return (strcmp(pref->mKey, otherKey) == 0); -} - struct CallbackNode { const char* mDomain; @@ -282,9 +281,9 @@ static bool gShouldCleanupDeadNodes = false; static PLDHashTableOps pref_HashTableOps = { PLDHashTable::HashStringKey, - MatchPrefEntry, + PrefHashEntry::MatchEntry, PLDHashTable::MoveEntryStub, - ClearPrefEntry, + PrefHashEntry::ClearEntry, nullptr, };