diff --git a/dom/base/nsContentList.cpp b/dom/base/nsContentList.cpp index bcdf11abe589..0021011bdb43 100644 --- a/dom/base/nsContentList.cpp +++ b/dom/base/nsContentList.cpp @@ -208,6 +208,8 @@ NS_GetContentList(nsINode* aRootNode, static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, ContentListHashtableHashKey, ContentListHashtableMatchEntry, PL_DHashMoveEntryStub, @@ -318,6 +320,8 @@ GetFuncStringContentList(nsINode* aRootNode, static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, FuncStringContentListHashtableHashKey, FuncStringContentListHashtableMatchEntry, PL_DHashMoveEntryStub, diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 7738c7cac5c1..ac4bb1d93e32 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -479,6 +479,8 @@ nsContentUtils::Init() if (!sEventListenerManagersHash.ops) { static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub, diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 0b3797929cfe..483465c0b256 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -3972,6 +3972,8 @@ nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc) static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub, diff --git a/dom/base/nsScriptNameSpaceManager.cpp b/dom/base/nsScriptNameSpaceManager.cpp index 6811dc07d988..61693bd1e9fd 100644 --- a/dom/base/nsScriptNameSpaceManager.cpp +++ b/dom/base/nsScriptNameSpaceManager.cpp @@ -320,6 +320,8 @@ nsScriptNameSpaceManager::Init() { static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, GlobalNameHashHashKey, GlobalNameHashMatchEntry, PL_DHashMoveEntryStub, diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index 2e90e013df0e..dd5f816ba7ee 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -760,6 +760,8 @@ XULDocument::AddBroadcastListenerFor(Element& aBroadcaster, Element& aListener, } static const PLDHashTableOps gOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub, diff --git a/embedding/components/commandhandler/nsCommandParams.cpp b/embedding/components/commandhandler/nsCommandParams.cpp index 79aaa69e4e77..e476b3e72f4f 100644 --- a/embedding/components/commandhandler/nsCommandParams.cpp +++ b/embedding/components/commandhandler/nsCommandParams.cpp @@ -16,6 +16,8 @@ using namespace mozilla; const PLDHashTableOps nsCommandParams::sHashOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashKey, HashMatchEntry, HashMoveEntry, diff --git a/gfx/thebes/gfxFT2FontList.cpp b/gfx/thebes/gfxFT2FontList.cpp index 7bf8cd99809a..6c2f8c7a990e 100644 --- a/gfx/thebes/gfxFT2FontList.cpp +++ b/gfx/thebes/gfxFT2FontList.cpp @@ -622,6 +622,8 @@ public: : mWriteNeeded(false) { mOps = (PLDHashTableOps) { + PL_DHashAllocTable, + PL_DHashFreeTable, StringHash, HashMatchEntry, MoveEntry, diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index c70846f570bb..342f9ea8d8bd 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -212,6 +212,8 @@ Native2WrappedNativeMap::SizeOfEntryExcludingThis(PLDHashEntryHdr *hdr, const struct PLDHashTableOps IID2WrappedJSClassMap::Entry::sOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashIIDPtrKey, MatchIIDPtrKey, PL_DHashMoveEntryStub, @@ -246,6 +248,8 @@ IID2WrappedJSClassMap::~IID2WrappedJSClassMap() const struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashIIDPtrKey, MatchIIDPtrKey, PL_DHashMoveEntryStub, @@ -448,6 +452,8 @@ NativeSetMap::Entry::Match(PLDHashTable *table, const struct PLDHashTableOps NativeSetMap::Entry::sOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashNativeKey, Match, PL_DHashMoveEntryStub, @@ -512,6 +518,8 @@ IID2ThisTranslatorMap::Entry::Clear(PLDHashTable *table, PLDHashEntryHdr *entry) const struct PLDHashTableOps IID2ThisTranslatorMap::Entry::sOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashIIDPtrKey, Match, PL_DHashMoveEntryStub, @@ -588,6 +596,8 @@ XPCNativeScriptableSharedMap::Entry::Match(PLDHashTable *table, const struct PLDHashTableOps XPCNativeScriptableSharedMap::Entry::sOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, Hash, Match, PL_DHashMoveEntryStub, diff --git a/layout/base/nsFrameManager.cpp b/layout/base/nsFrameManager.cpp index e415153577d0..027396731127 100644 --- a/layout/base/nsFrameManager.cpp +++ b/layout/base/nsFrameManager.cpp @@ -69,6 +69,8 @@ PlaceholderMapMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr, } static const PLDHashTableOps PlaceholderMapOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PlaceholderMapMatchEntry, PL_DHashMoveEntryStub, diff --git a/layout/style/nsCSSRuleProcessor.cpp b/layout/style/nsCSSRuleProcessor.cpp index b2c4ec6c9a18..c8fedcfc48bd 100644 --- a/layout/style/nsCSSRuleProcessor.cpp +++ b/layout/style/nsCSSRuleProcessor.cpp @@ -362,6 +362,8 @@ RuleHash_NameSpaceTable_MatchEntry(PLDHashTable *table, } static const PLDHashTableOps RuleHash_TagTable_Ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, RuleHash_TagTable_MatchEntry, RuleHash_TagTable_MoveEntry, @@ -372,6 +374,8 @@ static const PLDHashTableOps RuleHash_TagTable_Ops = { // Case-sensitive ops. static const RuleHashTableOps RuleHash_ClassTable_CSOps = { { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, RuleHash_CSMatchEntry, RuleHash_MoveEntry, @@ -384,6 +388,8 @@ static const RuleHashTableOps RuleHash_ClassTable_CSOps = { // Case-insensitive ops. static const RuleHashTableOps RuleHash_ClassTable_CIOps = { { + PL_DHashAllocTable, + PL_DHashFreeTable, RuleHash_CIHashKey, RuleHash_CIMatchEntry, RuleHash_MoveEntry, @@ -396,6 +402,8 @@ static const RuleHashTableOps RuleHash_ClassTable_CIOps = { // Case-sensitive ops. static const RuleHashTableOps RuleHash_IdTable_CSOps = { { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, RuleHash_CSMatchEntry, RuleHash_MoveEntry, @@ -408,6 +416,8 @@ static const RuleHashTableOps RuleHash_IdTable_CSOps = { // Case-insensitive ops. static const RuleHashTableOps RuleHash_IdTable_CIOps = { { + PL_DHashAllocTable, + PL_DHashFreeTable, RuleHash_CIHashKey, RuleHash_CIMatchEntry, RuleHash_MoveEntry, @@ -418,6 +428,8 @@ static const RuleHashTableOps RuleHash_IdTable_CIOps = { }; static const PLDHashTableOps RuleHash_NameSpaceTable_Ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, RuleHash_NameSpaceTable_HashKey, RuleHash_NameSpaceTable_MatchEntry, RuleHash_MoveEntry, @@ -875,6 +887,8 @@ AtomSelector_GetKey(PLDHashTable *table, const PLDHashEntryHdr *hdr) // Case-sensitive ops. static const PLDHashTableOps AtomSelector_CSOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, AtomSelector_MoveEntry, @@ -885,6 +899,8 @@ static const PLDHashTableOps AtomSelector_CSOps = { // Case-insensitive ops. static const RuleHashTableOps AtomSelector_CIOps = { { + PL_DHashAllocTable, + PL_DHashFreeTable, RuleHash_CIHashKey, RuleHash_CIMatchEntry, AtomSelector_MoveEntry, @@ -3321,6 +3337,8 @@ InitWeightEntry(PLDHashTable *table, PLDHashEntryHdr *hdr, } static const PLDHashTableOps gRulesByWeightOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashIntKey, MatchWeightEntry, PL_DHashMoveEntryStub, diff --git a/layout/style/nsHTMLStyleSheet.cpp b/layout/style/nsHTMLStyleSheet.cpp index 80a34b6cad8e..1184501ac7c2 100644 --- a/layout/style/nsHTMLStyleSheet.cpp +++ b/layout/style/nsHTMLStyleSheet.cpp @@ -169,6 +169,8 @@ MappedAttrTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr, } static const PLDHashTableOps MappedAttrTable_Ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, MappedAttrTable_HashKey, MappedAttrTable_MatchEntry, PL_DHashMoveEntryStub, @@ -223,6 +225,8 @@ LangRuleTable_InitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr, } static const PLDHashTableOps LangRuleTable_Ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, LangRuleTable_HashKey, LangRuleTable_MatchEntry, PL_DHashMoveEntryStub, diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index 180a8bfe6479..eb63ba2306e0 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -114,6 +114,8 @@ nsRuleNode::ChildrenHashOps = { // free rather than the pres shell's arena because the table doesn't // grow very often and the pres shell's arena doesn't recycle very // large size allocations. + PL_DHashAllocTable, + PL_DHashFreeTable, ChildrenHashHashKey, ChildrenHashMatchEntry, PL_DHashMoveEntryStub, diff --git a/layout/tables/SpanningCellSorter.cpp b/layout/tables/SpanningCellSorter.cpp index a9f7c542b026..28c68e53da67 100644 --- a/layout/tables/SpanningCellSorter.cpp +++ b/layout/tables/SpanningCellSorter.cpp @@ -33,6 +33,8 @@ SpanningCellSorter::~SpanningCellSorter() /* static */ const PLDHashTableOps SpanningCellSorter::HashTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashTableHashKey, HashTableMatchEntry, PL_DHashMoveEntryStub, diff --git a/modules/libpref/prefapi.cpp b/modules/libpref/prefapi.cpp index a4f534086eb3..51424ff285df 100644 --- a/modules/libpref/prefapi.cpp +++ b/modules/libpref/prefapi.cpp @@ -77,6 +77,8 @@ static bool gShouldCleanupDeadNodes = false; static PLDHashTableOps pref_HashTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashStringKey, matchPrefEntry, PL_DHashMoveEntryStub, diff --git a/netwerk/base/src/nsLoadGroup.cpp b/netwerk/base/src/nsLoadGroup.cpp index 4cc74cfcc1db..153590baae6e 100644 --- a/netwerk/base/src/nsLoadGroup.cpp +++ b/netwerk/base/src/nsLoadGroup.cpp @@ -1156,6 +1156,8 @@ nsresult nsLoadGroup::Init() { static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, RequestHashMatchEntry, PL_DHashMoveEntryStub, diff --git a/netwerk/cache/nsCacheEntry.cpp b/netwerk/cache/nsCacheEntry.cpp index 56735d683fdc..bd8b8a24c558 100644 --- a/netwerk/cache/nsCacheEntry.cpp +++ b/netwerk/cache/nsCacheEntry.cpp @@ -377,6 +377,8 @@ nsCacheEntryInfo::IsStreamBased(bool * result) const PLDHashTableOps nsCacheEntryHashTable::ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashKey, MatchEntry, MoveEntry, diff --git a/netwerk/cache/nsDiskCacheBinding.cpp b/netwerk/cache/nsDiskCacheBinding.cpp index 7356bfc0ef1b..24b6c48831f7 100644 --- a/netwerk/cache/nsDiskCacheBinding.cpp +++ b/netwerk/cache/nsDiskCacheBinding.cpp @@ -124,6 +124,8 @@ nsDiskCacheBinding::EnsureStreamIO() const PLDHashTableOps nsDiskCacheBindery::ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, HashKey, MatchEntry, MoveEntry, diff --git a/netwerk/dns/nsHostResolver.cpp b/netwerk/dns/nsHostResolver.cpp index 9a36663f591c..165ce2d0254a 100644 --- a/netwerk/dns/nsHostResolver.cpp +++ b/netwerk/dns/nsHostResolver.cpp @@ -463,6 +463,8 @@ HostDB_InitEntry(PLDHashTable *table, static const PLDHashTableOps gHostDB_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, HostDB_HashKey, HostDB_MatchEntry, HostDB_MoveEntry, diff --git a/netwerk/protocol/http/nsHttp.cpp b/netwerk/protocol/http/nsHttp.cpp index 5f49d8a2a5ce..45154f33ef62 100644 --- a/netwerk/protocol/http/nsHttp.cpp +++ b/netwerk/protocol/http/nsHttp.cpp @@ -42,7 +42,7 @@ struct HttpHeapAtom { char value[1]; }; -static PLDHashTable sAtomTable; +static struct PLDHashTable sAtomTable; static struct HttpHeapAtom *sHeapAtoms = nullptr; static Mutex *sLock = nullptr; @@ -85,6 +85,8 @@ StringCompare(PLDHashTable *table, const PLDHashEntryHdr *entry, } static const PLDHashTableOps ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, StringHash, StringCompare, PL_DHashMoveEntryStub, diff --git a/parser/htmlparser/nsHTMLEntities.cpp b/parser/htmlparser/nsHTMLEntities.cpp index 9120ca85ad25..68ca4135d15e 100644 --- a/parser/htmlparser/nsHTMLEntities.cpp +++ b/parser/htmlparser/nsHTMLEntities.cpp @@ -52,6 +52,8 @@ static PLDHashNumber static const PLDHashTableOps EntityToUnicodeOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashStringKey, matchNodeString, PL_DHashMoveEntryStub, @@ -60,6 +62,8 @@ static const PLDHashTableOps EntityToUnicodeOps = { }; static const PLDHashTableOps UnicodeToEntityOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, hashUnicodeValue, matchNodeUnicode, PL_DHashMoveEntryStub, diff --git a/rdf/base/nsRDFService.cpp b/rdf/base/nsRDFService.cpp index 94539dd8d88e..5c34b8895e85 100644 --- a/rdf/base/nsRDFService.cpp +++ b/rdf/base/nsRDFService.cpp @@ -140,6 +140,8 @@ struct ResourceHashEntry : public PLDHashEntryHdr { }; static const PLDHashTableOps gResourceTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, ResourceHashEntry::HashKey, ResourceHashEntry::MatchEntry, PL_DHashMoveEntryStub, @@ -175,6 +177,8 @@ struct LiteralHashEntry : public PLDHashEntryHdr { }; static const PLDHashTableOps gLiteralTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, LiteralHashEntry::HashKey, LiteralHashEntry::MatchEntry, PL_DHashMoveEntryStub, @@ -209,6 +213,8 @@ struct IntHashEntry : public PLDHashEntryHdr { }; static const PLDHashTableOps gIntTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, IntHashEntry::HashKey, IntHashEntry::MatchEntry, PL_DHashMoveEntryStub, @@ -247,6 +253,8 @@ struct DateHashEntry : public PLDHashEntryHdr { }; static const PLDHashTableOps gDateTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, DateHashEntry::HashKey, DateHashEntry::MatchEntry, PL_DHashMoveEntryStub, @@ -364,6 +372,8 @@ struct BlobHashEntry : public PLDHashEntryHdr { }; static const PLDHashTableOps gBlobTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, BlobHashEntry::HashKey, BlobHashEntry::MatchEntry, PL_DHashMoveEntryStub, diff --git a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp index 936d0e07a1cd..f064cc43e62c 100644 --- a/security/manager/boot/src/nsSecureBrowserUIImpl.cpp +++ b/security/manager/boot/src/nsSecureBrowserUIImpl.cpp @@ -80,6 +80,8 @@ RequestMapInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr, } static const PLDHashTableOps gMapOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, RequestMapMatchEntry, PL_DHashMoveEntryStub, diff --git a/security/manager/ssl/src/nsCertTree.cpp b/security/manager/ssl/src/nsCertTree.cpp index e6ffa179919f..58d6265510e6 100644 --- a/security/manager/ssl/src/nsCertTree.cpp +++ b/security/manager/ssl/src/nsCertTree.cpp @@ -92,6 +92,8 @@ CompareCacheClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr) } static const PLDHashTableOps gMapOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, CompareCacheMatchEntry, PL_DHashMoveEntryStub, diff --git a/security/manager/ssl/src/nsNSSShutDown.cpp b/security/manager/ssl/src/nsNSSShutDown.cpp index 93e091384e89..1f42a0674455 100644 --- a/security/manager/ssl/src/nsNSSShutDown.cpp +++ b/security/manager/ssl/src/nsNSSShutDown.cpp @@ -33,6 +33,8 @@ ObjectSetInitEntry(PLDHashTable *table, PLDHashEntryHdr *hdr, } static const PLDHashTableOps gSetOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, ObjectSetMatchEntry, PL_DHashMoveEntryStub, diff --git a/uriloader/base/nsDocLoader.cpp b/uriloader/base/nsDocLoader.cpp index 312de92c05d0..7eb458ed15cc 100644 --- a/uriloader/base/nsDocLoader.cpp +++ b/uriloader/base/nsDocLoader.cpp @@ -114,6 +114,8 @@ nsDocLoader::nsDocLoader() static const PLDHashTableOps hash_table_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub, diff --git a/xpcom/base/nsCycleCollector.cpp b/xpcom/base/nsCycleCollector.cpp index e6b9c5429165..f7b4f4b5391c 100644 --- a/xpcom/base/nsCycleCollector.cpp +++ b/xpcom/base/nsCycleCollector.cpp @@ -801,6 +801,8 @@ PtrToNodeMatchEntry(PLDHashTable* aTable, } static PLDHashTableOps PtrNodeOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PtrToNodeMatchEntry, PL_DHashMoveEntryStub, diff --git a/xpcom/ds/nsAtomTable.cpp b/xpcom/ds/nsAtomTable.cpp index 2d302ab3fb99..f8a698f9334b 100644 --- a/xpcom/ds/nsAtomTable.cpp +++ b/xpcom/ds/nsAtomTable.cpp @@ -288,6 +288,8 @@ AtomTableInitEntry(PLDHashTable* aTable, PLDHashEntryHdr* aEntry, static const PLDHashTableOps AtomTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, AtomTableGetHash, AtomTableMatchKey, PL_DHashMoveEntryStub, diff --git a/xpcom/ds/nsPersistentProperties.cpp b/xpcom/ds/nsPersistentProperties.cpp index 3de7134b0152..6b9f28cc8421 100644 --- a/xpcom/ds/nsPersistentProperties.cpp +++ b/xpcom/ds/nsPersistentProperties.cpp @@ -50,6 +50,8 @@ ArenaStrdup(const nsAFlatCString& aString, PLArenaPool* aArena) } static const struct PLDHashTableOps property_HashTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashStringKey, PL_DHashMatchStringKey, PL_DHashMoveEntryStub, diff --git a/xpcom/ds/nsPersistentProperties.h b/xpcom/ds/nsPersistentProperties.h index ef50f8cf6a3e..2b5f195b463e 100644 --- a/xpcom/ds/nsPersistentProperties.h +++ b/xpcom/ds/nsPersistentProperties.h @@ -33,7 +33,7 @@ protected: nsCOMPtr mIn; nsIPersistentProperties* mSubclass; - PLDHashTable mTable; + struct PLDHashTable mTable; PLArenaPool mArena; }; diff --git a/xpcom/ds/nsStaticNameTable.cpp b/xpcom/ds/nsStaticNameTable.cpp index 09663f72153b..df18d75fc564 100644 --- a/xpcom/ds/nsStaticNameTable.cpp +++ b/xpcom/ds/nsStaticNameTable.cpp @@ -94,6 +94,8 @@ caseInsensitiveStringHashKey(PLDHashTable* aTable, const void* aKey) } static const struct PLDHashTableOps nametable_CaseInsensitiveHashTableOps = { + PL_DHashAllocTable, + PL_DHashFreeTable, caseInsensitiveStringHashKey, matchNameKeysCaseInsensitive, PL_DHashMoveEntryStub, diff --git a/xpcom/glue/nsTHashtable.h b/xpcom/glue/nsTHashtable.h index bd3ccc1f3e80..c01c71bf43f3 100644 --- a/xpcom/glue/nsTHashtable.h +++ b/xpcom/glue/nsTHashtable.h @@ -419,6 +419,8 @@ nsTHashtable::Init(uint32_t aInitLength) { static const PLDHashTableOps sOps = { + ::PL_DHashAllocTable, + ::PL_DHashFreeTable, s_HashKey, s_MatchEntry, EntryType::ALLOW_MEMMOVE ? ::PL_DHashMoveEntryStub : s_CopyEntry, diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index bde970a27c5c..df2ecc74d2e0 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -68,6 +68,18 @@ using namespace mozilla; +void* +PL_DHashAllocTable(PLDHashTable* aTable, uint32_t aNBytes) +{ + return malloc(aNBytes); +} + +void +PL_DHashFreeTable(PLDHashTable* aTable, void* aPtr) +{ + free(aPtr); +} + PLDHashNumber PL_DHashStringKey(PLDHashTable* aTable, const void* aKey) { @@ -146,6 +158,8 @@ PL_DHashFreeStringKey(PLDHashTable* aTable, PLDHashEntryHdr* aEntry) } static const PLDHashTableOps stub_ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, PL_DHashVoidPtrKeyStub, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub, @@ -171,13 +185,13 @@ PLDHashTable* PL_NewDHashTable(const PLDHashTableOps* aOps, uint32_t aEntrySize, uint32_t aLength) { - PLDHashTable* table = (PLDHashTable*)malloc(sizeof(*table)); + PLDHashTable* table = (PLDHashTable*)aOps->allocTable(NULL, sizeof(*table)); if (!table) { return nullptr; } if (!PL_DHashTableInit(table, aOps, aEntrySize, fallible_t(), aLength)) { - free(table); + aOps->freeTable(NULL, table); return nullptr; } return table; @@ -187,7 +201,7 @@ void PL_DHashTableDestroy(PLDHashTable* aTable) { PL_DHashTableFinish(aTable); - free(aTable); + aTable->ops->freeTable(NULL, aTable); } /* @@ -249,7 +263,7 @@ PLDHashTable::Init(const PLDHashTableOps* aOps, return false; // overflowed } - mEntryStore = (char*)malloc(nbytes); + mEntryStore = (char*)aOps->allocTable(this, nbytes); if (!mEntryStore) { return false; } @@ -338,7 +352,7 @@ PLDHashTable::Finish() MOZ_ASSERT(RECURSION_LEVEL_SAFE_TO_FINISH(this)); /* Free entry storage last. */ - free(mEntryStore); + ops->freeTable(this, mEntryStore); } void @@ -481,7 +495,7 @@ PLDHashTable::ChangeTable(int aDeltaLog2) return false; // overflowed } - char* newEntryStore = (char*)malloc(nbytes); + char* newEntryStore = (char*)ops->allocTable(this, nbytes); if (!newEntryStore) { return false; } @@ -520,7 +534,7 @@ PLDHashTable::ChangeTable(int aDeltaLog2) oldEntryAddr += mEntrySize; } - free(oldEntryStore); + ops->freeTable(this, oldEntryStore); return true; } diff --git a/xpcom/glue/pldhash.h b/xpcom/glue/pldhash.h index 8a6c2d21c232..a7ffb59c6e4a 100644 --- a/xpcom/glue/pldhash.h +++ b/xpcom/glue/pldhash.h @@ -53,10 +53,12 @@ #define PL_DHASH_BITS 32 #define PL_DHASH_GOLDEN_RATIO 0x9E3779B9U -typedef uint32_t PLDHashNumber; - -class PLDHashTable; -struct PLDHashTableOps; +/* Primitive and forward-struct typedefs. */ +typedef uint32_t PLDHashNumber; +typedef struct PLDHashEntryHdr PLDHashEntryHdr; +typedef struct PLDHashEntryStub PLDHashEntryStub; +typedef struct PLDHashTable PLDHashTable; +typedef struct PLDHashTableOps PLDHashTableOps; /* * Table entry header structure. @@ -174,9 +176,8 @@ typedef size_t (*PLDHashSizeOfEntryExcludingThisFun)( * aTable->mGeneration before adding or removing, and compare the sample after, * dereferencing the entry pointer only if aTable->mGeneration has not changed. */ -class PLDHashTable +struct PLDHashTable { -public: /* * Virtual operations; see below. This field is public because it's commonly * zeroed to indicate that a table is no longer live. @@ -299,6 +300,15 @@ private: bool ChangeTable(int aDeltaLog2); }; +/* + * Table space at mEntryStore is allocated and freed using these callbacks. + * The allocator should return null on error only (not if called with aNBytes + * equal to 0; but note that pldhash.c code will never call with 0 aNBytes). + */ +typedef void* (*PLDHashAllocTable)(PLDHashTable* aTable, uint32_t aNBytes); + +typedef void (*PLDHashFreeTable)(PLDHashTable* aTable, void* aPtr); + /* * Compute the hash code for a given key to be looked up, added, or removed * from aTable. A hash code may have any PLDHashNumber value. @@ -343,11 +353,13 @@ typedef bool (*PLDHashInitEntry)(PLDHashTable* aTable, PLDHashEntryHdr* aEntry, const void* aKey); /* - * Finally, the "vtable" structure for PLDHashTable. The first four hooks + * Finally, the "vtable" structure for PLDHashTable. The first six hooks * must be provided by implementations; they're called unconditionally by the * generic pldhash.c code. Hooks after these may be null. * * Summary of allocation-related hook usage with C++ placement new emphasis: + * allocTable Allocate raw bytes with malloc, no ctors run. + * freeTable Free raw bytes with free, no dtors run. * initEntry Call placement new using default key-based ctor. * Return true on success, false on error. * moveEntry Call placement new using copy ctor, run dtor on old @@ -368,6 +380,8 @@ typedef bool (*PLDHashInitEntry)(PLDHashTable* aTable, PLDHashEntryHdr* aEntry, struct PLDHashTableOps { /* Mandatory hooks. All implementations must provide these. */ + PLDHashAllocTable allocTable; + PLDHashFreeTable freeTable; PLDHashHashKey hashKey; PLDHashMatchEntry matchEntry; PLDHashMoveEntry moveEntry; @@ -380,6 +394,9 @@ struct PLDHashTableOps /* * Default implementations for the above ops. */ +void* PL_DHashAllocTable(PLDHashTable* aTable, uint32_t aNBytes); + +void PL_DHashFreeTable(PLDHashTable* aTable, void* aPtr); PLDHashNumber PL_DHashStringKey(PLDHashTable* aTable, const void* aKey); @@ -417,8 +434,10 @@ void PL_DHashFreeStringKey(PLDHashTable* aTable, PLDHashEntryHdr* aEntry); const PLDHashTableOps* PL_DHashGetStubOps(void); /* - * Dynamically allocate a new PLDHashTable, initialize it using - * PL_DHashTableInit, and return its address. Return null on allocation failure. + * Dynamically allocate a new PLDHashTable using malloc, initialize it using + * PL_DHashTableInit, and return its address. Return null on malloc failure. + * Note that the entry storage at aTable->mEntryStore will be allocated using + * the aOps->allocTable callback. */ PLDHashTable* PL_NewDHashTable( const PLDHashTableOps* aOps, uint32_t aEntrySize, @@ -472,9 +491,9 @@ void PL_DHashTableFinish(PLDHashTable* aTable); * entry = PL_DHashTableOperate(table, key, PL_DHASH_ADD); * * If entry is null upon return, then either the table is severely overloaded, - * and memory can't be allocated for entry storage. Or if - * aTable->ops->initEntry is non-null, the aTable->ops->initEntry op may have - * returned false. + * and memory can't be allocated for entry storage via aTable->ops->allocTable; + * Or if aTable->ops->initEntry is non-null, the aTable->ops->initEntry op may + * have returned false. * * Otherwise, aEntry->keyHash has been set so that PL_DHASH_ENTRY_IS_BUSY(entry) * is true, and it is up to the caller to initialize the key and value parts diff --git a/xpcom/tests/TestPLDHash.cpp b/xpcom/tests/TestPLDHash.cpp index d465670c281a..81a8aa91f340 100644 --- a/xpcom/tests/TestPLDHash.cpp +++ b/xpcom/tests/TestPLDHash.cpp @@ -80,6 +80,8 @@ hash(PLDHashTable *table, const void *key) static bool test_pldhash_grow_to_max_capacity() { static const PLDHashTableOps ops = { + PL_DHashAllocTable, + PL_DHashFreeTable, hash, PL_DHashMatchEntryStub, PL_DHashMoveEntryStub,