From 77943547dc1f13c5065b5ed21b102b48110fefae Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 4 May 2015 22:59:24 -0700 Subject: [PATCH] Bug 1161377 (part 2) - Remove PL_NewDHashTable() and PL_DHashTableDestroy(). r=froydnj. They're not needed now that there is an initializing constructor and a destructor. --- dom/base/nsDocument.cpp | 22 +++++---------- dom/xul/XULDocument.cpp | 6 ++--- js/xpconnect/src/XPCMaps.cpp | 45 +++++++++++++------------------ layout/style/nsRuleNode.cpp | 6 ++--- rdf/base/nsInMemoryDataSource.cpp | 4 +-- xpcom/glue/pldhash.cpp | 16 ----------- xpcom/glue/pldhash.h | 15 ----------- xpcom/tests/TestPLDHash.cpp | 6 ++--- 8 files changed, 35 insertions(+), 85 deletions(-) diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index b84f6d8d3540..c0642e7fa94e 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -1719,11 +1719,8 @@ nsDocument::~nsDocument() // Kill the subdocument map, doing this will release its strong // references, if any. - if (mSubDocuments) { - PL_DHashTableDestroy(mSubDocuments); - - mSubDocuments = nullptr; - } + delete mSubDocuments; + mSubDocuments = nullptr; // Destroy link map now so we don't waste time removing // links one by one @@ -2127,10 +2124,8 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsDocument) tmp->mStyleSheetSetList = nullptr; } - if (tmp->mSubDocuments) { - PL_DHashTableDestroy(tmp->mSubDocuments); - tmp->mSubDocuments = nullptr; - } + delete tmp->mSubDocuments; + tmp->mSubDocuments = nullptr; tmp->mFrameRequestCallbacks.Clear(); @@ -2328,11 +2323,8 @@ nsDocument::ResetToURI(nsIURI *aURI, nsILoadGroup *aLoadGroup, // Delete references to sub-documents and kill the subdocument map, // if any. It holds strong references - if (mSubDocuments) { - PL_DHashTableDestroy(mSubDocuments); - - mSubDocuments = nullptr; - } + delete mSubDocuments; + mSubDocuments = nullptr; // Destroy link map now so we don't waste time removing // links one by one @@ -4039,7 +4031,7 @@ nsDocument::SetSubDocumentFor(Element* aElement, nsIDocument* aSubDoc) SubDocInitEntry }; - mSubDocuments = PL_NewDHashTable(&hash_table_ops, sizeof(SubDocMapEntry)); + mSubDocuments = new PLDHashTable(&hash_table_ops, sizeof(SubDocMapEntry)); } // Add a mapping to the hash table diff --git a/dom/xul/XULDocument.cpp b/dom/xul/XULDocument.cpp index cea57fe6324f..ec02e245036d 100644 --- a/dom/xul/XULDocument.cpp +++ b/dom/xul/XULDocument.cpp @@ -217,9 +217,7 @@ XULDocument::~XULDocument() mPersistenceIds.Clear(); // Destroy our broadcaster map. - if (mBroadcasterMap) { - PL_DHashTableDestroy(mBroadcasterMap); - } + delete mBroadcasterMap; delete mTemplateBuilderTable; @@ -771,7 +769,7 @@ XULDocument::AddBroadcastListenerFor(Element& aBroadcaster, Element& aListener, }; if (! mBroadcasterMap) { - mBroadcasterMap = PL_NewDHashTable(&gOps, sizeof(BroadcasterMapEntry)); + mBroadcasterMap = new PLDHashTable(&gOps, sizeof(BroadcasterMapEntry)); } BroadcasterMapEntry* entry = diff --git a/js/xpconnect/src/XPCMaps.cpp b/js/xpconnect/src/XPCMaps.cpp index 8c297eaa836c..0c1e51f4b410 100644 --- a/js/xpconnect/src/XPCMaps.cpp +++ b/js/xpconnect/src/XPCMaps.cpp @@ -182,13 +182,12 @@ Native2WrappedNativeMap::newMap(int length) Native2WrappedNativeMap::Native2WrappedNativeMap(int length) { - mTable = PL_NewDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); + mTable = new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); } Native2WrappedNativeMap::~Native2WrappedNativeMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } size_t @@ -231,13 +230,12 @@ IID2WrappedJSClassMap::newMap(int length) IID2WrappedJSClassMap::IID2WrappedJSClassMap(int length) { - mTable = PL_NewDHashTable(&Entry::sOps, sizeof(Entry), length); + mTable = new PLDHashTable(&Entry::sOps, sizeof(Entry), length); } IID2WrappedJSClassMap::~IID2WrappedJSClassMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } @@ -265,13 +263,12 @@ IID2NativeInterfaceMap::newMap(int length) IID2NativeInterfaceMap::IID2NativeInterfaceMap(int length) { - mTable = PL_NewDHashTable(&Entry::sOps, sizeof(Entry), length); + mTable = new PLDHashTable(&Entry::sOps, sizeof(Entry), length); } IID2NativeInterfaceMap::~IID2NativeInterfaceMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } size_t @@ -307,13 +304,12 @@ ClassInfo2NativeSetMap::newMap(int length) ClassInfo2NativeSetMap::ClassInfo2NativeSetMap(int length) { - mTable = PL_NewDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); + mTable = new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); } ClassInfo2NativeSetMap::~ClassInfo2NativeSetMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } size_t @@ -346,13 +342,12 @@ ClassInfo2WrappedNativeProtoMap::newMap(int length) ClassInfo2WrappedNativeProtoMap::ClassInfo2WrappedNativeProtoMap(int length) { - mTable = PL_NewDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); + mTable = new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry), length); } ClassInfo2WrappedNativeProtoMap::~ClassInfo2WrappedNativeProtoMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } size_t @@ -467,13 +462,12 @@ NativeSetMap::newMap(int length) NativeSetMap::NativeSetMap(int length) { - mTable = PL_NewDHashTable(&Entry::sOps, sizeof(Entry), length); + mTable = new PLDHashTable(&Entry::sOps, sizeof(Entry), length); } NativeSetMap::~NativeSetMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } size_t @@ -531,13 +525,12 @@ IID2ThisTranslatorMap::newMap(int length) IID2ThisTranslatorMap::IID2ThisTranslatorMap(int length) { - mTable = PL_NewDHashTable(&Entry::sOps, sizeof(Entry), length); + mTable = new PLDHashTable(&Entry::sOps, sizeof(Entry), length); } IID2ThisTranslatorMap::~IID2ThisTranslatorMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } /***************************************************************************/ @@ -608,13 +601,12 @@ XPCNativeScriptableSharedMap::newMap(int length) XPCNativeScriptableSharedMap::XPCNativeScriptableSharedMap(int length) { - mTable = PL_NewDHashTable(&Entry::sOps, sizeof(Entry), length); + mTable = new PLDHashTable(&Entry::sOps, sizeof(Entry), length); } XPCNativeScriptableSharedMap::~XPCNativeScriptableSharedMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } bool @@ -660,14 +652,13 @@ XPCWrappedNativeProtoMap::newMap(int length) XPCWrappedNativeProtoMap::XPCWrappedNativeProtoMap(int length) { - mTable = PL_NewDHashTable(PL_DHashGetStubOps(), + mTable = new PLDHashTable(PL_DHashGetStubOps(), sizeof(PLDHashEntryStub), length); } XPCWrappedNativeProtoMap::~XPCWrappedNativeProtoMap() { - if (mTable) - PL_DHashTableDestroy(mTable); + delete mTable; } /***************************************************************************/ diff --git a/layout/style/nsRuleNode.cpp b/layout/style/nsRuleNode.cpp index d9253dd1ffab..5abe1351547e 100644 --- a/layout/style/nsRuleNode.cpp +++ b/layout/style/nsRuleNode.cpp @@ -1431,7 +1431,7 @@ nsRuleNode::DestroyInternal(nsRuleNode ***aDestroyQueueTail) PL_DHashTableEnumerate(children, EnqueueRuleNodeChildren, &destroyQueueTail); *destroyQueueTail = nullptr; // ensure null-termination - PL_DHashTableDestroy(children); + delete children; } else if (HaveChildren()) { *destroyQueueTail = ChildrenList(); do { @@ -1614,7 +1614,7 @@ nsRuleNode::ConvertChildrenToHash(int32_t aNumKids) { NS_ASSERTION(!ChildrenAreHashed() && HaveChildren(), "must have a non-empty list of children"); - PLDHashTable *hash = PL_NewDHashTable(&ChildrenHashOps, + PLDHashTable *hash = new PLDHashTable(&ChildrenHashOps, sizeof(ChildrenHashEntry), aNumKids); for (nsRuleNode* curr = ChildrenList(); curr; curr = curr->mNextSibling) { @@ -9372,7 +9372,7 @@ nsRuleNode::SweepChildren(nsTArray& aSweepQueue) PL_DHashTableEnumerate(children, SweepHashEntry, &survivorsWithChildren); childrenDestroyed = oldChildCount - children->EntryCount(); if (childrenDestroyed == oldChildCount) { - PL_DHashTableDestroy(children); + delete children; mChildren.asVoid = nullptr; } } else { diff --git a/rdf/base/nsInMemoryDataSource.cpp b/rdf/base/nsInMemoryDataSource.cpp index 87dd8d7df232..a064b4983dd4 100644 --- a/rdf/base/nsInMemoryDataSource.cpp +++ b/rdf/base/nsInMemoryDataSource.cpp @@ -163,7 +163,7 @@ Assertion::Assertion(nsIRDFResource* aSource) NS_ADDREF(mSource); u.hash.mPropertyHash = - PL_NewDHashTable(PL_DHashGetStubOps(), sizeof(Entry)); + new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry)); } Assertion::Assertion(nsIRDFResource* aSource, @@ -194,7 +194,7 @@ Assertion::~Assertion() if (mHashEntry && u.hash.mPropertyHash) { PL_DHashTableEnumerate(u.hash.mPropertyHash, DeletePropertyHashEntry, nullptr); - PL_DHashTableDestroy(u.hash.mPropertyHash); + delete u.hash.mPropertyHash; u.hash.mPropertyHash = nullptr; } diff --git a/xpcom/glue/pldhash.cpp b/xpcom/glue/pldhash.cpp index 0c9e25a83b21..4871cd69fc89 100644 --- a/xpcom/glue/pldhash.cpp +++ b/xpcom/glue/pldhash.cpp @@ -169,22 +169,6 @@ SizeOfEntryStore(uint32_t aCapacity, uint32_t aEntrySize, uint32_t* aNbytes) return uint64_t(*aNbytes) == nbytes64; // returns false on overflow } -PLDHashTable* -PL_NewDHashTable(const PLDHashTableOps* aOps, uint32_t aEntrySize, - uint32_t aLength) -{ - PLDHashTable* table = new PLDHashTable(); - PL_DHashTableInit(table, aOps, aEntrySize, aLength); - return table; -} - -void -PL_DHashTableDestroy(PLDHashTable* aTable) -{ - PL_DHashTableFinish(aTable); - delete aTable; -} - /* * Compute max and min load numbers (entry counts). We have a secondary max * that allows us to overload a table reasonably if it cannot be grown further diff --git a/xpcom/glue/pldhash.h b/xpcom/glue/pldhash.h index 8e3c8b02b1dd..3899dea8f9f0 100644 --- a/xpcom/glue/pldhash.h +++ b/xpcom/glue/pldhash.h @@ -476,21 +476,6 @@ 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. Never returns null. - */ -PLDHashTable* PL_NewDHashTable( - const PLDHashTableOps* aOps, uint32_t aEntrySize, - uint32_t aLength = PL_DHASH_DEFAULT_INITIAL_LENGTH); - -/* - * Free |aTable|'s entry storage and |aTable| itself (both via - * aTable->mOps->freeTable). Use this function to destroy a PLDHashTable that - * was allocated on the heap via PL_NewDHashTable(). - */ -void PL_DHashTableDestroy(PLDHashTable* aTable); - /* * This function works similarly to the multi-arg constructor. * diff --git a/xpcom/tests/TestPLDHash.cpp b/xpcom/tests/TestPLDHash.cpp index 9ba7db413f5f..6823816d71f9 100644 --- a/xpcom/tests/TestPLDHash.cpp +++ b/xpcom/tests/TestPLDHash.cpp @@ -186,11 +186,11 @@ static bool test_pldhash_grow_to_max_capacity() }; // This is infallible. - PLDHashTable* t = PL_NewDHashTable(&ops, sizeof(PLDHashEntryStub), 128); + PLDHashTable* t = new PLDHashTable(&ops, sizeof(PLDHashEntryStub), 128); // Check that New() sets |t->ops|. if (!t->IsInitialized()) { - PL_DHashTableDestroy(t); + delete t; return false; } @@ -209,7 +209,7 @@ static bool test_pldhash_grow_to_max_capacity() return false; } - PL_DHashTableDestroy(t); + delete t; return true; }