Bug 1166598 (part 5) - Use PLDHashTable2 in InMemoryDataSource. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Tue, 05 May 2015 18:39:20 -0700
changeset 245435 5a9cc200b499fa96275d95386f226e67e2756a72
parent 245434 b373d9cab11f7689aca59920ea67d6cb188666f1
child 245436 d2b79df6cb618d50c80e4c6b5a577e8c171ed1f7
push id28806
push userphilringnalda@gmail.com
push dateTue, 26 May 2015 02:10:16 +0000
treeherdermozilla-central@4362d9251296 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1166598
milestone41.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 1166598 (part 5) - Use PLDHashTable2 in InMemoryDataSource. r=froydnj.
rdf/base/nsInMemoryDataSource.cpp
--- a/rdf/base/nsInMemoryDataSource.cpp
+++ b/rdf/base/nsInMemoryDataSource.cpp
@@ -245,18 +245,18 @@ class InMemoryDataSource : public nsIRDF
                            public rdfIDataSource
 {
 protected:
     // These hash tables are keyed on pointers to nsIRDFResource
     // objects (the nsIRDFService ensures that there is only ever one
     // nsIRDFResource object per unique URI). The value of an entry is
     // an Assertion struct, which is a linked list of (subject
     // predicate object) triples.
-    PLDHashTable mForwardArcs; 
-    PLDHashTable mReverseArcs; 
+    PLDHashTable2 mForwardArcs;
+    PLDHashTable2 mReverseArcs;
 
     nsCOMArray<nsIRDFObserver> mObservers;  
     uint32_t                   mNumObservers;
 
     // VisitFoo needs to block writes, [Un]Assert only allowed
     // during mReadCount == 0
     uint32_t mReadCount;
 
@@ -281,17 +281,16 @@ protected:
 
     nsresult
     LockedUnassert(nsIRDFResource* source,
                    nsIRDFResource* property,
                    nsIRDFNode* target);
 
     explicit InMemoryDataSource(nsISupports* aOuter);
     virtual ~InMemoryDataSource();
-    nsresult Init();
 
     friend nsresult
     NS_NewRDFInMemoryDataSource(nsISupports* aOuter, const nsIID& aIID, void** aResult);
 
 public:
     NS_DECL_CYCLE_COLLECTING_AGGREGATED
     NS_DECL_AGGREGATED_CYCLE_COLLECTION_CLASS(InMemoryDataSource)
 
@@ -747,72 +746,57 @@ NS_NewRDFInMemoryDataSource(nsISupports*
     *aResult = nullptr;
 
     if (aOuter && !aIID.Equals(NS_GET_IID(nsISupports))) {
         NS_ERROR("aggregation requires nsISupports");
         return NS_ERROR_ILLEGAL_VALUE;
     }
 
     InMemoryDataSource* datasource = new InMemoryDataSource(aOuter);
-    if (! datasource)
-        return NS_ERROR_OUT_OF_MEMORY;
     NS_ADDREF(datasource);
 
-    nsresult rv = datasource->Init();
-    if (NS_SUCCEEDED(rv)) {
-        datasource->fAggregated.AddRef();
-        rv = datasource->AggregatedQueryInterface(aIID, aResult); // This'll AddRef()
-        datasource->fAggregated.Release();
-    }
+    datasource->fAggregated.AddRef();
+    nsresult rv = datasource->AggregatedQueryInterface(aIID, aResult); // This'll AddRef()
+    datasource->fAggregated.Release();
 
     NS_RELEASE(datasource);
     return rv;
 }
 
 
 InMemoryDataSource::InMemoryDataSource(nsISupports* aOuter)
-    : mNumObservers(0), mReadCount(0)
+    : mForwardArcs(PL_DHashGetStubOps(), sizeof(Entry))
+    , mReverseArcs(PL_DHashGetStubOps(), sizeof(Entry))
+    , mNumObservers(0)
+    , mReadCount(0)
 {
     NS_INIT_AGGREGATED(aOuter);
 
     mPropagateChanges = true;
     MOZ_COUNT_CTOR(InMemoryDataSource);
-}
-
-
-nsresult
-InMemoryDataSource::Init()
-{
-    PL_DHashTableInit(&mForwardArcs, PL_DHashGetStubOps(), sizeof(Entry));
-    PL_DHashTableInit(&mReverseArcs, PL_DHashGetStubOps(), sizeof(Entry));
 
     if (! gLog)
         gLog = PR_NewLogModule("InMemoryDataSource");
-
-    return NS_OK;
 }
 
 
 InMemoryDataSource::~InMemoryDataSource()
 {
 #ifdef DEBUG_REFS
     --gInstanceCount;
     fprintf(stdout, "%d - RDF: InMemoryDataSource\n", gInstanceCount);
 #endif
 
-    if (mForwardArcs.IsInitialized()) {
+    if (mForwardArcs.EntryCount() > 0) {
         // This'll release all of the Assertion objects that are
         // associated with this data source. We only need to do this
         // for the forward arcs, because the reverse arcs table
         // indexes the exact same set of resources.
         PL_DHashTableEnumerate(&mForwardArcs, DeleteForwardArcsEntry, nullptr);
-        PL_DHashTableFinish(&mForwardArcs);
     }
-    if (mReverseArcs.IsInitialized())
-        PL_DHashTableFinish(&mReverseArcs);
 
     MOZ_LOG(gLog, PR_LOG_NOTICE,
            ("InMemoryDataSource(%p): destroyed.", this));
 
     MOZ_COUNT_DTOR(InMemoryDataSource);
 }
 
 PLDHashOperator