Bug 1161377 (part 2) - Remove PL_NewDHashTable() and PL_DHashTableDestroy(). r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Mon, 04 May 2015 22:59:24 -0700
changeset 274253 2eae1608bcfadd5cacbc41e05fc225a92757832e
parent 274252 3d8e382a1e451964b27f6fbb3be9abdfcc18900f
child 274254 c375efe78e070322db1cbfcf7b373ab1c6830e17
push id863
push userraliiev@mozilla.com
push dateMon, 03 Aug 2015 13:22:43 +0000
treeherdermozilla-release@f6321b14228d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1161377
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/xul/XULDocument.cpp
js/xpconnect/src/XPCMaps.cpp
layout/style/nsRuleNode.cpp
rdf/base/nsInMemoryDataSource.cpp
xpcom/glue/pldhash.cpp
xpcom/glue/pldhash.h
xpcom/tests/TestPLDHash.cpp
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -1714,21 +1714,18 @@ nsDocument::~nsDocument()
   if (mAnimationController) {
     mAnimationController->Disconnect();
   }
 
   mParentDocument = nullptr;
 
   // 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
   DestroyElementMaps();
 
   nsAutoScriptBlocker scriptBlocker;
 
   int32_t indx; // must be signed
@@ -2122,20 +2119,18 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(ns
 
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mDOMStyleSheets)
 
   if (tmp->mStyleSheetSetList) {
     tmp->mStyleSheetSetList->Disconnect();
     tmp->mStyleSheetSetList = nullptr;
   }
 
-  if (tmp->mSubDocuments) {
-    PL_DHashTableDestroy(tmp->mSubDocuments);
-    tmp->mSubDocuments = nullptr;
-  }
+  delete tmp->mSubDocuments;
+  tmp->mSubDocuments = nullptr;
 
   tmp->mFrameRequestCallbacks.Clear();
 
   tmp->mRadioGroups.Clear();
 
   // nsDocument has a pretty complex destructor, so we're going to
   // assume that *most* cycles you actually want to break somewhere
   // else, and not unlink an awful lot here.
@@ -2323,21 +2318,18 @@ nsDocument::ResetToURI(nsIURI *aURI, nsI
 #endif
 
   mSecurityInfo = nullptr;
 
   mDocumentLoadGroup = nullptr;
 
   // 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
   DestroyElementMaps();
 
   bool oldVal = mInUnlinkOrDeletion;
   mInUnlinkOrDeletion = true;
   uint32_t count = mChildren.ChildCount();
@@ -4034,17 +4026,17 @@ nsDocument::SetSubDocumentFor(Element* a
       {
         PL_DHashVoidPtrKeyStub,
         PL_DHashMatchEntryStub,
         PL_DHashMoveEntryStub,
         SubDocClearEntry,
         SubDocInitEntry
       };
 
-      mSubDocuments = PL_NewDHashTable(&hash_table_ops, sizeof(SubDocMapEntry));
+      mSubDocuments = new PLDHashTable(&hash_table_ops, sizeof(SubDocMapEntry));
     }
 
     // Add a mapping to the hash table
     SubDocMapEntry *entry = static_cast<SubDocMapEntry*>
       (PL_DHashTableAdd(mSubDocuments, aElement, fallible));
 
     if (!entry) {
       return NS_ERROR_OUT_OF_MEMORY;
--- a/dom/xul/XULDocument.cpp
+++ b/dom/xul/XULDocument.cpp
@@ -212,19 +212,17 @@ XULDocument::~XULDocument()
     // In case we failed somewhere early on and the forward observer
     // decls never got resolved.
     mForwardReferences.Clear();
     // Likewise for any references we have to IDs where we might
     // look for persisted data:
     mPersistenceIds.Clear();
 
     // Destroy our broadcaster map.
-    if (mBroadcasterMap) {
-        PL_DHashTableDestroy(mBroadcasterMap);
-    }
+    delete mBroadcasterMap;
 
     delete mTemplateBuilderTable;
 
     Preferences::UnregisterCallback(XULDocument::DirectionChanged,
                                     "intl.uidirection.", this);
 
     if (mOffThreadCompileStringBuf) {
       js_free(mOffThreadCompileStringBuf);
@@ -766,17 +764,17 @@ XULDocument::AddBroadcastListenerFor(Ele
         PL_DHashVoidPtrKeyStub,
         PL_DHashMatchEntryStub,
         PL_DHashMoveEntryStub,
         ClearBroadcasterMapEntry,
         nullptr
     };
 
     if (! mBroadcasterMap) {
-        mBroadcasterMap = PL_NewDHashTable(&gOps, sizeof(BroadcasterMapEntry));
+        mBroadcasterMap = new PLDHashTable(&gOps, sizeof(BroadcasterMapEntry));
     }
 
     BroadcasterMapEntry* entry =
         static_cast<BroadcasterMapEntry*>
                    (PL_DHashTableSearch(mBroadcasterMap, &aBroadcaster));
 
     if (!entry) {
         entry = static_cast<BroadcasterMapEntry*>
--- a/js/xpconnect/src/XPCMaps.cpp
+++ b/js/xpconnect/src/XPCMaps.cpp
@@ -177,23 +177,22 @@ Native2WrappedNativeMap::newMap(int leng
     // to use the map, so we abort immediately to provide a more
     // useful crash stack.
     NS_RUNTIMEABORT("Ran out of memory.");
     return nullptr;
 }
 
 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
 Native2WrappedNativeMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
 {
     size_t n = 0;
     n += mallocSizeOf(this);
     n += mTable ? PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf) : 0;
@@ -226,23 +225,22 @@ IID2WrappedJSClassMap::newMap(int length
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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;
 }
 
 
 /***************************************************************************/
 // implement IID2NativeInterfaceMap...
 
 const struct PLDHashTableOps IID2NativeInterfaceMap::Entry::sOps =
 {
@@ -260,23 +258,22 @@ IID2NativeInterfaceMap::newMap(int lengt
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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
 IID2NativeInterfaceMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
 {
     size_t n = 0;
     n += mallocSizeOf(this);
     n += mTable ? PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf) : 0;
@@ -302,23 +299,22 @@ ClassInfo2NativeSetMap::newMap(int lengt
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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
 ClassInfo2NativeSetMap::ShallowSizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
 {
     size_t n = 0;
     n += mallocSizeOf(this);
     // The second arg is nullptr because this is a "shallow" measurement of the map.
@@ -341,23 +337,22 @@ ClassInfo2WrappedNativeProtoMap::newMap(
     // to use the map, so we abort immediately to provide a more
     // useful crash stack.
     NS_RUNTIMEABORT("Ran out of memory.");
     return nullptr;
 }
 
 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
 ClassInfo2WrappedNativeProtoMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
 {
     size_t n = 0;
     n += mallocSizeOf(this);
     n += mTable ? PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf) : 0;
@@ -462,23 +457,22 @@ NativeSetMap::newMap(int length)
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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
 NativeSetMap::SizeOfIncludingThis(mozilla::MallocSizeOf mallocSizeOf)
 {
     size_t n = 0;
     n += mallocSizeOf(this);
     n += mTable ? PL_DHashTableSizeOfIncludingThis(mTable, SizeOfEntryExcludingThis, mallocSizeOf) : 0;
@@ -526,23 +520,22 @@ IID2ThisTranslatorMap::newMap(int length
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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;
 }
 
 /***************************************************************************/
 
 PLDHashNumber
 XPCNativeScriptableSharedMap::Entry::Hash(PLDHashTable* table, const void* key)
 {
     PLDHashNumber h;
@@ -603,23 +596,22 @@ XPCNativeScriptableSharedMap::newMap(int
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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
 XPCNativeScriptableSharedMap::GetNewOrUsed(uint32_t flags,
                                            char* name,
                                            XPCNativeScriptableInfo* si)
 {
     NS_PRECONDITION(name,"bad param");
@@ -655,19 +647,18 @@ XPCWrappedNativeProtoMap::newMap(int len
     if (map && map->mTable)
         return map;
     delete map;
     return nullptr;
 }
 
 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;
 }
 
 /***************************************************************************/
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1426,17 +1426,17 @@ nsRuleNode::DestroyInternal(nsRuleNode *
     destroyQueueTail = &destroyQueue;
   }
 
   if (ChildrenAreHashed()) {
     PLDHashTable *children = ChildrenHash();
     PL_DHashTableEnumerate(children, EnqueueRuleNodeChildren,
                            &destroyQueueTail);
     *destroyQueueTail = nullptr; // ensure null-termination
-    PL_DHashTableDestroy(children);
+    delete children;
   } else if (HaveChildren()) {
     *destroyQueueTail = ChildrenList();
     do {
       destroyQueueTail = &(*destroyQueueTail)->mNextSibling;
     } while (*destroyQueueTail);
   }
   mChildren.asVoid = nullptr;
 
@@ -1609,17 +1609,17 @@ void nsRuleNode::SetUsedDirectly()
   }
 }
 
 void
 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) {
     // This will never fail because of the initial size we gave the table.
     ChildrenHashEntry *entry = static_cast<ChildrenHashEntry*>(
       PL_DHashTableAdd(hash, curr->mRule, fallible));
     NS_ASSERTION(!entry->mRuleNode, "duplicate entries in list");
     entry->mRuleNode = curr;
@@ -9367,17 +9367,17 @@ nsRuleNode::SweepChildren(nsTArray<nsRul
   uint32_t childrenDestroyed = 0;
   nsRuleNode* survivorsWithChildren = nullptr;
   if (ChildrenAreHashed()) {
     PLDHashTable* children = ChildrenHash();
     uint32_t oldChildCount = children->EntryCount();
     PL_DHashTableEnumerate(children, SweepHashEntry, &survivorsWithChildren);
     childrenDestroyed = oldChildCount - children->EntryCount();
     if (childrenDestroyed == oldChildCount) {
-      PL_DHashTableDestroy(children);
+      delete children;
       mChildren.asVoid = nullptr;
     }
   } else {
     for (nsRuleNode** children = ChildrenListPtr(); *children; ) {
       nsRuleNode* next = (*children)->mNextSibling;
       if ((*children)->DestroyIfNotMarked()) {
         // This rule node was destroyed, unlink it from the list by
         // making *children point to the next entry.
--- a/rdf/base/nsInMemoryDataSource.cpp
+++ b/rdf/base/nsInMemoryDataSource.cpp
@@ -158,17 +158,17 @@ Assertion::Assertion(nsIRDFResource* aSo
       mRefCnt(0),
       mHashEntry(true)
 {
     MOZ_COUNT_CTOR(Assertion);
 
     NS_ADDREF(mSource);
 
     u.hash.mPropertyHash =
-        PL_NewDHashTable(PL_DHashGetStubOps(), sizeof(Entry));
+        new PLDHashTable(PL_DHashGetStubOps(), sizeof(Entry));
 }
 
 Assertion::Assertion(nsIRDFResource* aSource,
                      nsIRDFResource* aProperty,
                      nsIRDFNode* aTarget,
                      bool aTruthValue)
     : mSource(aSource),
       mNext(nullptr),
@@ -189,17 +189,17 @@ Assertion::Assertion(nsIRDFResource* aSo
     u.as.mMarked = false;
 }
 
 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;
     }
 
     MOZ_COUNT_DTOR(Assertion);
 #ifdef DEBUG_REFS
     --gInstanceCount;
     fprintf(stdout, "%d - RDF: Assertion\n", gInstanceCount);
 #endif
--- a/xpcom/glue/pldhash.cpp
+++ b/xpcom/glue/pldhash.cpp
@@ -164,32 +164,16 @@ PL_DHashGetStubOps(void)
 static bool
 SizeOfEntryStore(uint32_t aCapacity, uint32_t aEntrySize, uint32_t* aNbytes)
 {
   uint64_t nbytes64 = uint64_t(aCapacity) * uint64_t(aEntrySize);
   *aNbytes = aCapacity * aEntrySize;
   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
  * (i.e. if ChangeTable() fails).  The table slows down drastically if the
  * secondary max is too close to 1, but 0.96875 gives only a slight slowdown
  * while allowing 1.3x more elements.
  */
 static inline uint32_t
--- a/xpcom/glue/pldhash.h
+++ b/xpcom/glue/pldhash.h
@@ -472,31 +472,16 @@ void PL_DHashFreeStringKey(PLDHashTable*
 /*
  * If you use PLDHashEntryStub or a subclass of it as your entry struct, and
  * if your entries move via memcpy and clear via memset(0), you can use these
  * stub operations.
  */
 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.
  *
  * Any table initialized with this function must be finalized via
  * PL_DHashTableFinish(). The alternative (and preferred) way to
  * initialize a PLDHashTable is via the multi-arg constructor; any such table
  * will be auto-finalized by the destructor.
  */
 void PL_DHashTableInit(
--- a/xpcom/tests/TestPLDHash.cpp
+++ b/xpcom/tests/TestPLDHash.cpp
@@ -181,21 +181,21 @@ static bool test_pldhash_grow_to_max_cap
     trivial_hash,
     PL_DHashMatchEntryStub,
     PL_DHashMoveEntryStub,
     PL_DHashClearEntryStub,
     nullptr
   };
 
   // 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;
   }
 
   // Keep inserting elements until failure occurs because the table is full.
   size_t numInserted = 0;
   while (true) {
     if (!PL_DHashTableAdd(t, (const void*)numInserted, mozilla::fallible)) {
       break;
@@ -204,17 +204,17 @@ static bool test_pldhash_grow_to_max_cap
   }
 
   // We stop when the element count is 96.875% of PL_DHASH_MAX_SIZE (see
   // MaxLoadOnGrowthFailure()).
   if (numInserted != PL_DHASH_MAX_CAPACITY - (PL_DHASH_MAX_CAPACITY >> 5)) {
     return false;
   }
 
-  PL_DHashTableDestroy(t);
+  delete t;
 
   return true;
 }
 #endif
 
 //----
 
 typedef bool (*TestFunc)();