Bug 847248 (part 4) - Remove all uses of nsFixedSizeAllocator from rdf/. r=bz.

--HG--
extra : rebase_source : 0b8c23f48155ef89972452a74682283d2191d02c
This commit is contained in:
Nicholas Nethercote 2013-03-04 01:16:19 -08:00
parent 808d69f25e
commit e094959051
2 changed files with 68 additions and 261 deletions

View File

@ -27,7 +27,6 @@
*/
#include "xpcom-config.h"
#include NEW_H
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsIEnumerator.h"
@ -35,7 +34,6 @@
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFRemoteDataSource.h"
#include "nsFixedSizeAllocator.h"
#include "nsTArray.h"
#include "nsCOMArray.h"
#include "nsArrayEnumerator.h"
@ -93,13 +91,11 @@ protected:
nsCOMArray<nsIRDFObserver> mObservers;
nsCOMArray<nsIRDFDataSource> mDataSources;
bool mAllowNegativeAssertions;
bool mCoalesceDuplicateArcs;
bool mAllowNegativeAssertions;
bool mCoalesceDuplicateArcs;
int32_t mUpdateBatchNest;
nsFixedSizeAllocator mAllocator;
virtual ~CompositeDataSourceImpl() {}
virtual ~CompositeDataSourceImpl() {}
friend class CompositeEnumeratorImpl;
friend class CompositeArcsInOutEnumeratorImpl;
@ -126,15 +122,13 @@ class CompositeEnumeratorImpl : public nsISimpleEnumerator
virtual nsresult
HasNegation(nsIRDFDataSource* aDataSource, nsIRDFNode* aNode, bool* aResult) = 0;
virtual void Destroy() = 0;
protected:
CompositeEnumeratorImpl(CompositeDataSourceImpl* aCompositeDataSource,
bool aAllowNegativeAssertions,
bool aCoalesceDuplicateArcs);
virtual ~CompositeEnumeratorImpl();
CompositeDataSourceImpl* mCompositeDataSource;
nsISimpleEnumerator* mCurrent;
@ -156,19 +150,19 @@ CompositeEnumeratorImpl::CompositeEnumeratorImpl(CompositeDataSourceImpl* aCompo
mAllowNegativeAssertions(aAllowNegativeAssertions),
mCoalesceDuplicateArcs(aCoalesceDuplicateArcs)
{
NS_ADDREF(mCompositeDataSource);
NS_ADDREF(mCompositeDataSource);
}
CompositeEnumeratorImpl::~CompositeEnumeratorImpl(void)
{
NS_IF_RELEASE(mCurrent);
NS_IF_RELEASE(mResult);
NS_RELEASE(mCompositeDataSource);
NS_IF_RELEASE(mCurrent);
NS_IF_RELEASE(mResult);
NS_RELEASE(mCompositeDataSource);
}
NS_IMPL_ADDREF(CompositeEnumeratorImpl)
NS_IMPL_RELEASE_WITH_DESTROY(CompositeEnumeratorImpl, Destroy())
NS_IMPL_RELEASE(CompositeEnumeratorImpl)
NS_IMPL_QUERY_INTERFACE1(CompositeEnumeratorImpl, nsISimpleEnumerator)
NS_IMETHODIMP
@ -330,21 +324,6 @@ class CompositeArcsInOutEnumeratorImpl : public CompositeEnumeratorImpl
public:
enum Type { eArcsIn, eArcsOut };
static CompositeArcsInOutEnumeratorImpl*
Create(nsFixedSizeAllocator& aAllocator,
CompositeDataSourceImpl* aCompositeDataSource,
nsIRDFNode* aNode,
Type aType,
bool aAllowNegativeAssertions,
bool aCoalesceDuplicateArcs) {
void* place = aAllocator.Alloc(sizeof(CompositeArcsInOutEnumeratorImpl));
return place
? ::new (place) CompositeArcsInOutEnumeratorImpl(aCompositeDataSource,
aNode, aType,
aAllowNegativeAssertions,
aCoalesceDuplicateArcs)
: nullptr; }
virtual ~CompositeArcsInOutEnumeratorImpl();
virtual nsresult
@ -353,9 +332,6 @@ public:
virtual nsresult
HasNegation(nsIRDFDataSource* aDataSource, nsIRDFNode* aNode, bool* aResult);
virtual void Destroy();
protected:
CompositeArcsInOutEnumeratorImpl(CompositeDataSourceImpl* aCompositeDataSource,
nsIRDFNode* aNode,
Type aType,
@ -365,11 +341,6 @@ protected:
private:
nsIRDFNode* mNode;
Type mType;
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) {}
};
@ -416,18 +387,6 @@ CompositeArcsInOutEnumeratorImpl::HasNegation(
return NS_OK;
}
void
CompositeArcsInOutEnumeratorImpl::Destroy()
{
// Keep the datasource alive for the duration of the stack
// frame so its allocator stays valid.
nsCOMPtr<nsIRDFCompositeDataSource> kungFuDeathGrip = mCompositeDataSource;
nsFixedSizeAllocator& pool = mCompositeDataSource->mAllocator;
this->~CompositeArcsInOutEnumeratorImpl();
pool.Free(this, sizeof(*this));
}
//----------------------------------------------------------------------
//
@ -437,33 +396,12 @@ CompositeArcsInOutEnumeratorImpl::Destroy()
class CompositeAssertionEnumeratorImpl : public CompositeEnumeratorImpl
{
public:
static CompositeAssertionEnumeratorImpl*
Create(nsFixedSizeAllocator& aAllocator,
CompositeDataSourceImpl* aCompositeDataSource,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
bool aTruthValue,
bool aAllowNegativeAssertions,
bool aCoalesceDuplicateArcs) {
void* place = aAllocator.Alloc(sizeof(CompositeAssertionEnumeratorImpl));
return place
? ::new (place) CompositeAssertionEnumeratorImpl(aCompositeDataSource,
aSource, aProperty, aTarget,
aTruthValue,
aAllowNegativeAssertions,
aCoalesceDuplicateArcs)
: nullptr; }
virtual nsresult
GetEnumerator(nsIRDFDataSource* aDataSource, nsISimpleEnumerator** aResult);
virtual nsresult
HasNegation(nsIRDFDataSource* aDataSource, nsIRDFNode* aNode, bool* aResult);
virtual void Destroy();
protected:
CompositeAssertionEnumeratorImpl(CompositeDataSourceImpl* aCompositeDataSource,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
@ -479,11 +417,6 @@ private:
nsIRDFResource* mProperty;
nsIRDFNode* mTarget;
bool mTruthValue;
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) {}
};
@ -542,18 +475,6 @@ CompositeAssertionEnumeratorImpl::HasNegation(
}
}
void
CompositeAssertionEnumeratorImpl::Destroy()
{
// Keep the datasource alive for the duration of the stack
// frame so its allocator stays valid.
nsCOMPtr<nsIRDFCompositeDataSource> kungFuDeathGrip = mCompositeDataSource;
nsFixedSizeAllocator& pool = mCompositeDataSource->mAllocator;
this->~CompositeAssertionEnumeratorImpl();
pool.Free(this, sizeof(*this));
}
////////////////////////////////////////////////////////////////////////
nsresult
@ -574,17 +495,6 @@ CompositeDataSourceImpl::CompositeDataSourceImpl(void)
mCoalesceDuplicateArcs(true),
mUpdateBatchNest(0)
{
static const size_t kBucketSizes[] = {
sizeof(CompositeAssertionEnumeratorImpl),
sizeof(CompositeArcsInOutEnumeratorImpl) };
static const int32_t kNumBuckets = sizeof(kBucketSizes) / sizeof(size_t);
// Per news://news.mozilla.org/39BEC105.5090206%40netscape.com
static const int32_t kInitialSize = 256;
mAllocator.Init("nsCompositeDataSource", kBucketSizes, kNumBuckets, kInitialSize);
#ifdef PR_LOGGING
if (nsRDFLog == nullptr)
nsRDFLog = PR_NewLogModule("RDF");
@ -686,11 +596,10 @@ CompositeDataSourceImpl::GetSources(nsIRDFResource* aProperty,
if (! mAllowNegativeAssertions && ! aTruthValue)
return(NS_RDF_NO_VALUE);
*aResult = CompositeAssertionEnumeratorImpl::Create(mAllocator,
this, nullptr, aProperty,
aTarget, aTruthValue,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
*aResult = new CompositeAssertionEnumeratorImpl(this, nullptr, aProperty,
aTarget, aTruthValue,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
if (! *aResult)
return NS_ERROR_OUT_OF_MEMORY;
@ -793,11 +702,11 @@ CompositeDataSourceImpl::GetTargets(nsIRDFResource* aSource,
return(NS_RDF_NO_VALUE);
*aResult =
CompositeAssertionEnumeratorImpl::Create(mAllocator, this,
aSource, aProperty, nullptr,
aTruthValue,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
new CompositeAssertionEnumeratorImpl(this,
aSource, aProperty, nullptr,
aTruthValue,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
if (! *aResult)
return NS_ERROR_OUT_OF_MEMORY;
@ -1124,11 +1033,11 @@ CompositeDataSourceImpl::ArcLabelsIn(nsIRDFNode* aTarget, nsISimpleEnumerator**
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsISimpleEnumerator* result =
CompositeArcsInOutEnumeratorImpl::Create(mAllocator, this, aTarget,
CompositeArcsInOutEnumeratorImpl::eArcsIn,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
nsISimpleEnumerator* result =
new CompositeArcsInOutEnumeratorImpl(this, aTarget,
CompositeArcsInOutEnumeratorImpl::eArcsIn,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
@ -1151,10 +1060,10 @@ CompositeDataSourceImpl::ArcLabelsOut(nsIRDFResource* aSource,
return NS_ERROR_NULL_POINTER;
nsISimpleEnumerator* result =
CompositeArcsInOutEnumeratorImpl::Create(mAllocator, this, aSource,
CompositeArcsInOutEnumeratorImpl::eArcsOut,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
new CompositeArcsInOutEnumeratorImpl(this, aSource,
CompositeArcsInOutEnumeratorImpl::eArcsOut,
mAllowNegativeAssertions,
mCoalesceDuplicateArcs);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -60,7 +60,6 @@
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsXPIDLString.h"
#include "nsFixedSizeAllocator.h"
#include "rdfutil.h"
#include "pldhash.h"
#include "plstr.h"
@ -82,37 +81,9 @@ static PRLogModuleInfo* gLog = nullptr;
// ownership is shared between the datasource and any enumerators that
// are currently iterating over the datasource.
//
class Assertion
class Assertion
{
public:
static Assertion*
Create(nsFixedSizeAllocator& aAllocator,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
bool aTruthValue) {
void* place = aAllocator.Alloc(sizeof(Assertion));
return place
? ::new (place) Assertion(aSource, aProperty, aTarget, aTruthValue)
: nullptr; }
static Assertion*
Create(nsFixedSizeAllocator& aAllocator, nsIRDFResource* aSource) {
void* place = aAllocator.Alloc(sizeof(Assertion));
return place
? ::new (place) Assertion(aSource)
: nullptr; }
static void
Destroy(nsFixedSizeAllocator& aAllocator, Assertion* aAssertion) {
if (aAssertion->mHashEntry && aAssertion->u.hash.mPropertyHash) {
PL_DHashTableEnumerate(aAssertion->u.hash.mPropertyHash,
DeletePropertyHashEntry, &aAllocator);
PL_DHashTableDestroy(aAssertion->u.hash.mPropertyHash);
aAssertion->u.hash.mPropertyHash = nullptr;
}
aAssertion->~Assertion();
aAllocator.Free(aAssertion, sizeof(*aAssertion)); }
static PLDHashOperator
DeletePropertyHashEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
uint32_t aNumber, void* aArg);
@ -133,13 +104,13 @@ public:
++mRefCnt;
}
void Release(nsFixedSizeAllocator& aAllocator) {
void Release() {
if (mRefCnt == UINT16_MAX) {
NS_WARNING("refcount overflow, leaking Assertion");
return;
}
if (--mRefCnt == 0)
Destroy(aAllocator, this);
delete this;
}
// For nsIRDFPurgeableDataSource
@ -175,12 +146,6 @@ public:
// all 32-bit entries are long aligned
uint16_t mRefCnt;
bool mHashEntry;
private:
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) {}
};
@ -230,6 +195,13 @@ Assertion::Assertion(nsIRDFResource* aSource,
Assertion::~Assertion()
{
if (mHashEntry && u.hash.mPropertyHash) {
PL_DHashTableEnumerate(u.hash.mPropertyHash, DeletePropertyHashEntry,
NULL);
PL_DHashTableDestroy(u.hash.mPropertyHash);
u.hash.mPropertyHash = nullptr;
}
MOZ_COUNT_DTOR(RDF_Assertion);
#ifdef DEBUG_REFS
--gInstanceCount;
@ -249,7 +221,6 @@ Assertion::DeletePropertyHashEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
uint32_t aNumber, void* aArg)
{
Entry* entry = reinterpret_cast<Entry*>(aHdr);
nsFixedSizeAllocator* allocator = static_cast<nsFixedSizeAllocator*>(aArg);
Assertion* as = entry->mAssertions;
while (as) {
@ -258,7 +229,7 @@ Assertion::DeletePropertyHashEntry(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
// Unlink, and release the datasource's reference.
doomed->mNext = doomed->u.as.mInvNext = nullptr;
doomed->Release(*allocator);
doomed->Release();
}
return PL_DHASH_NEXT;
}
@ -278,8 +249,6 @@ class InMemoryDataSource : public nsIRDFDataSource,
public rdfIDataSource
{
protected:
nsFixedSizeAllocator mAllocator;
// 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
@ -418,11 +387,7 @@ private:
Assertion* mNextAssertion;
nsCOMPtr<nsISupportsArray> mHashArcs;
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) {}
public:
InMemoryAssertionEnumeratorImpl(InMemoryDataSource* aDataSource,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
@ -431,35 +396,9 @@ private:
virtual ~InMemoryAssertionEnumeratorImpl();
public:
static InMemoryAssertionEnumeratorImpl*
Create(InMemoryDataSource* aDataSource,
nsIRDFResource* aSource,
nsIRDFResource* aProperty,
nsIRDFNode* aTarget,
bool aTruthValue) {
void* place = aDataSource->mAllocator.Alloc(sizeof(InMemoryAssertionEnumeratorImpl));
return place
? ::new (place) InMemoryAssertionEnumeratorImpl(aDataSource,
aSource, aProperty, aTarget,
aTruthValue)
: nullptr; }
static void
Destroy(InMemoryAssertionEnumeratorImpl* aEnumerator) {
// Keep the datasource alive for the duration of the stack
// frame so its allocator stays valid.
nsCOMPtr<nsIRDFDataSource> kungFuDeathGrip = aEnumerator->mDataSource;
// Grab the pool from the datasource; since we keep the
// datasource alive, this has to be safe.
nsFixedSizeAllocator& pool = aEnumerator->mDataSource->mAllocator;
aEnumerator->~InMemoryAssertionEnumeratorImpl();
pool.Free(aEnumerator, sizeof(*aEnumerator)); }
// nsISupports interface
NS_DECL_ISUPPORTS
// nsISimpleEnumerator interface
NS_DECL_NSISIMPLEENUMERATOR
};
@ -515,7 +454,7 @@ InMemoryAssertionEnumeratorImpl::~InMemoryAssertionEnumeratorImpl()
#endif
if (mNextAssertion)
mNextAssertion->Release(mDataSource->mAllocator);
mNextAssertion->Release();
NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mSource);
@ -525,7 +464,7 @@ InMemoryAssertionEnumeratorImpl::~InMemoryAssertionEnumeratorImpl()
}
NS_IMPL_ADDREF(InMemoryAssertionEnumeratorImpl)
NS_IMPL_RELEASE_WITH_DESTROY(InMemoryAssertionEnumeratorImpl, Destroy(this))
NS_IMPL_RELEASE(InMemoryAssertionEnumeratorImpl)
NS_IMPL_QUERY_INTERFACE1(InMemoryAssertionEnumeratorImpl, nsISimpleEnumerator)
NS_IMETHODIMP
@ -562,7 +501,7 @@ InMemoryAssertionEnumeratorImpl::HasMoreElements(bool* aResult)
mNextAssertion->AddRef();
// ...and release the reference from the enumerator to the old one.
as->Release(mDataSource->mAllocator);
as->Release();
if (foundIt) {
*aResult = true;
@ -608,11 +547,6 @@ InMemoryAssertionEnumeratorImpl::GetNext(nsISupports** aResult)
class InMemoryArcsEnumeratorImpl : public nsISimpleEnumerator
{
private:
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
static void* operator new(size_t) CPP_THROW_NEW { return 0; }
static void operator delete(void*, size_t) {}
InMemoryDataSource* mDataSource;
nsIRDFResource* mSource;
nsIRDFNode* mTarget;
@ -621,43 +555,22 @@ private:
Assertion* mAssertion;
nsCOMPtr<nsISupportsArray> mHashArcs;
static PLDHashOperator
ArcEnumerator(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
uint32_t aNumber, void* aArg);
public:
InMemoryArcsEnumeratorImpl(InMemoryDataSource* aDataSource,
nsIRDFResource* aSource,
nsIRDFNode* aTarget);
virtual ~InMemoryArcsEnumeratorImpl();
static PLDHashOperator
ArcEnumerator(PLDHashTable* aTable, PLDHashEntryHdr* aHdr,
uint32_t aNumber, void* aArg);
public:
// nsISupports interface
NS_DECL_ISUPPORTS
// nsISimpleEnumerator interface
NS_DECL_NSISIMPLEENUMERATOR
static InMemoryArcsEnumeratorImpl*
Create(InMemoryDataSource* aDataSource,
nsIRDFResource* aSource,
nsIRDFNode* aTarget) {
void* place = aDataSource->mAllocator.Alloc(sizeof(InMemoryArcsEnumeratorImpl));
return place
? ::new (place) InMemoryArcsEnumeratorImpl(aDataSource, aSource, aTarget)
: nullptr; }
static void
Destroy(InMemoryArcsEnumeratorImpl* aEnumerator) {
// Keep the datasource alive for the duration of the stack
// frame so its allocator stays valid.
nsCOMPtr<nsIRDFDataSource> kungFuDeathGrip = aEnumerator->mDataSource;
// Grab the pool from the datasource; since we keep the
// datasource alive, this has to be safe.
nsFixedSizeAllocator& pool = aEnumerator->mDataSource->mAllocator;
aEnumerator->~InMemoryArcsEnumeratorImpl();
pool.Free(aEnumerator, sizeof(*aEnumerator)); }
};
@ -719,7 +632,7 @@ InMemoryArcsEnumeratorImpl::~InMemoryArcsEnumeratorImpl()
}
NS_IMPL_ADDREF(InMemoryArcsEnumeratorImpl)
NS_IMPL_RELEASE_WITH_DESTROY(InMemoryArcsEnumeratorImpl, Destroy(this))
NS_IMPL_RELEASE(InMemoryArcsEnumeratorImpl)
NS_IMPL_QUERY_INTERFACE1(InMemoryArcsEnumeratorImpl, nsISimpleEnumerator)
NS_IMETHODIMP
@ -853,19 +766,6 @@ InMemoryDataSource::InMemoryDataSource(nsISupports* aOuter)
{
NS_INIT_AGGREGATED(aOuter);
static const size_t kBucketSizes[] = {
sizeof(Assertion),
sizeof(Entry),
sizeof(InMemoryArcsEnumeratorImpl),
sizeof(InMemoryAssertionEnumeratorImpl) };
static const int32_t kNumBuckets = sizeof(kBucketSizes) / sizeof(size_t);
// Per news://news.mozilla.org/39BEC105.5090206%40netscape.com
static const int32_t kInitialSize = 1024;
mAllocator.Init("nsInMemoryDataSource", kBucketSizes, kNumBuckets, kInitialSize);
mForwardArcs.ops = nullptr;
mReverseArcs.ops = nullptr;
mPropagateChanges = true;
@ -913,7 +813,7 @@ InMemoryDataSource::~InMemoryDataSource()
// 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, &mAllocator);
PL_DHashTableEnumerate(&mForwardArcs, DeleteForwardArcsEntry, NULL);
PL_DHashTableFinish(&mForwardArcs);
}
if (mReverseArcs.ops)
@ -929,7 +829,6 @@ InMemoryDataSource::DeleteForwardArcsEntry(PLDHashTable* aTable, PLDHashEntryHdr
uint32_t aNumber, void* aArg)
{
Entry* entry = reinterpret_cast<Entry*>(aHdr);
nsFixedSizeAllocator* allocator = static_cast<nsFixedSizeAllocator*>(aArg);
Assertion* as = entry->mAssertions;
while (as) {
@ -938,7 +837,7 @@ InMemoryDataSource::DeleteForwardArcsEntry(PLDHashTable* aTable, PLDHashEntryHdr
// Unlink, and release the datasource's reference.
doomed->mNext = doomed->u.as.mInvNext = nullptr;
doomed->Release(*allocator);
doomed->Release();
}
return PL_DHASH_NEXT;
}
@ -1177,8 +1076,8 @@ InMemoryDataSource::GetSources(nsIRDFResource* aProperty,
return NS_ERROR_NULL_POINTER;
InMemoryAssertionEnumeratorImpl* result =
InMemoryAssertionEnumeratorImpl::Create(this, nullptr, aProperty,
aTarget, aTruthValue);
new InMemoryAssertionEnumeratorImpl(this, nullptr, aProperty,
aTarget, aTruthValue);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
@ -1198,7 +1097,7 @@ InMemoryDataSource::GetTargets(nsIRDFResource* aSource,
NS_PRECONDITION(aSource != nullptr, "null ptr");
if (! aSource)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aProperty != nullptr, "null ptr");
if (! aProperty)
return NS_ERROR_NULL_POINTER;
@ -1208,8 +1107,8 @@ InMemoryDataSource::GetTargets(nsIRDFResource* aSource,
return NS_ERROR_NULL_POINTER;
InMemoryAssertionEnumeratorImpl* result =
InMemoryAssertionEnumeratorImpl::Create(this, aSource, aProperty,
nullptr, aTruthValue);
new InMemoryAssertionEnumeratorImpl(this, aSource, aProperty,
nullptr, aTruthValue);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
@ -1269,7 +1168,7 @@ InMemoryDataSource::LockedAssert(nsIRDFResource* aSource,
}
}
as = Assertion::Create(mAllocator, aSource, aProperty, aTarget, aTruthValue);
as = new Assertion(aSource, aProperty, aTarget, aTruthValue);
if (! as)
return NS_ERROR_OUT_OF_MEMORY;
@ -1415,7 +1314,7 @@ InMemoryDataSource::LockedUnassert(nsIRDFResource* aSource,
else {
// If this second-level hash empties out, clean it up.
if (!root->u.hash.mPropertyHash->entryCount) {
Assertion::Destroy(mAllocator, root);
delete root;
SetForwardArcs(aSource, nullptr);
}
}
@ -1475,7 +1374,7 @@ InMemoryDataSource::LockedUnassert(nsIRDFResource* aSource,
// Unlink, and release the datasource's reference
as->mNext = as->u.as.mInvNext = nullptr;
as->Release(mAllocator);
as->Release();
return NS_OK;
}
@ -1714,7 +1613,7 @@ InMemoryDataSource::ArcLabelsIn(nsIRDFNode* aTarget, nsISimpleEnumerator** aResu
return NS_ERROR_NULL_POINTER;
InMemoryArcsEnumeratorImpl* result =
InMemoryArcsEnumeratorImpl::Create(this, nullptr, aTarget);
new InMemoryArcsEnumeratorImpl(this, nullptr, aTarget);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
@ -1733,7 +1632,7 @@ InMemoryDataSource::ArcLabelsOut(nsIRDFResource* aSource, nsISimpleEnumerator**
return NS_ERROR_NULL_POINTER;
InMemoryArcsEnumeratorImpl* result =
InMemoryArcsEnumeratorImpl::Create(this, aSource, nullptr);
new InMemoryArcsEnumeratorImpl(this, aSource, nullptr);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
@ -1824,13 +1723,13 @@ InMemoryDataSource::EnsureFastContainment(nsIRDFResource* aSource)
{
Assertion *as = GetForwardArcs(aSource);
bool haveHash = (as) ? as->mHashEntry : false;
// if its already a hash, then nothing to do
if (haveHash) return(NS_OK);
// convert aSource in forward hash into a hash
Assertion *hashAssertion = Assertion::Create(mAllocator, aSource);
NS_ASSERTION(hashAssertion, "unable to Assertion::Create");
Assertion *hashAssertion = new Assertion(aSource);
NS_ASSERTION(hashAssertion, "unable to create Assertion");
if (!hashAssertion) return(NS_ERROR_OUT_OF_MEMORY);
// Add the datasource's owning reference.
@ -1965,13 +1864,12 @@ InMemoryDataSource::Mark(nsIRDFResource* aSource,
struct SweepInfo {
Assertion* mUnassertList;
PLDHashTable* mReverseArcs;
nsFixedSizeAllocator* mAllocator;
};
NS_IMETHODIMP
InMemoryDataSource::Sweep()
{
SweepInfo info = { nullptr, &mReverseArcs, &mAllocator};
SweepInfo info = { nullptr, &mReverseArcs };
// Remove all the assertions, but don't notify anyone.
PL_DHashTableEnumerate(&mForwardArcs, SweepForwardArcsEntries, &info);
@ -1997,7 +1895,7 @@ InMemoryDataSource::Sweep()
// Unlink, and release the datasource's reference
doomed->mNext = doomed->u.as.mInvNext = nullptr;
doomed->Release(mAllocator);
doomed->Release();
}
return NS_OK;
@ -2017,12 +1915,12 @@ InMemoryDataSource::SweepForwardArcsEntries(PLDHashTable* aTable,
if (as && (as->mHashEntry))
{
// Stuff in sub-hashes must be swept recursively (max depth: 1)
PL_DHashTableEnumerate(as->u.hash.mPropertyHash,
PL_DHashTableEnumerate(as->u.hash.mPropertyHash,
SweepForwardArcsEntries, info);
// If the sub-hash is now empty, clean it up.
if (!as->u.hash.mPropertyHash->entryCount) {
Assertion::Destroy(*info->mAllocator, as);
delete as;
result = PL_DHASH_REMOVE;
}