Bug 847248 (part 5) - Remove nsFixedSizeAllocator from nsXULTemplateBuilder. r=enndeakin.

--HG--
extra : rebase_source : 5a90f5659f6fe8f5789add3206a1a556eeb098f9
This commit is contained in:
Nicholas Nethercote 2013-03-04 20:49:49 -08:00
Родитель 4177a8b753
Коммит f2ad32872a
6 изменённых файлов: 33 добавлений и 60 удалений

Просмотреть файл

@ -13,13 +13,11 @@ void nsTemplateMatch::operator=(const nsTemplateMatch& aMatch) {}
// static
void
nsTemplateMatch::Destroy(nsFixedSizeAllocator& aPool,
nsTemplateMatch*& aMatch,
bool aRemoveResult) {
nsTemplateMatch::Destroy(nsTemplateMatch*& aMatch, bool aRemoveResult)
{
if (aRemoveResult && aMatch->mResult)
aMatch->mResult->HasBeenRemoved();
aMatch->~nsTemplateMatch();
aPool.Free(aMatch, sizeof(*aMatch));
::delete aMatch;
aMatch = nullptr;
}

Просмотреть файл

@ -6,12 +6,10 @@
#ifndef nsTemplateMatch_h__
#define nsTemplateMatch_h__
#include "nsFixedSizeAllocator.h"
#include "nsIContent.h"
#include "nsIXULTemplateQueryProcessor.h"
#include "nsIXULTemplateResult.h"
#include "nsRuleNetwork.h"
#include NEW_H
/**
* A match object, where each match object is associated with one result.
@ -37,8 +35,8 @@ class nsTemplateMatch {
private:
// Hide so that only Create() and Destroy() can be used to
// allocate and deallocate from the heap
void* operator new(size_t) CPP_THROW_NEW { return 0; }
void operator delete(void*, size_t) {}
void* operator new(size_t) CPP_THROW_NEW { MOZ_ASSERT(0); return nullptr; }
void operator delete(void*, size_t) { MOZ_ASSERT(0); }
public:
nsTemplateMatch(uint16_t aQuerySetPriority,
@ -59,18 +57,13 @@ public:
}
static nsTemplateMatch*
Create(nsFixedSizeAllocator& aPool,
uint16_t aQuerySetPriority,
Create(uint16_t aQuerySetPriority,
nsIXULTemplateResult* aResult,
nsIContent* aContainer) {
void* place = aPool.Alloc(sizeof(nsTemplateMatch));
return place ? ::new (place) nsTemplateMatch(aQuerySetPriority,
aResult, aContainer)
: nullptr; }
return ::new nsTemplateMatch(aQuerySetPriority, aResult, aContainer);
}
static void Destroy(nsFixedSizeAllocator& aPool,
nsTemplateMatch*& aMatch,
bool aRemoveResult);
static void Destroy(nsTemplateMatch*& aMatch, bool aRemoveResult);
// return true if the the match is active, and has generated output
bool IsActive() {

Просмотреть файл

@ -1116,7 +1116,7 @@ nsXULContentBuilder::CreateContainerContentsForQuerySet(nsIContent* aElement,
continue;
nsTemplateMatch *newmatch =
nsTemplateMatch::Create(mPool, aQuerySet->Priority(),
nsTemplateMatch::Create(aQuerySet->Priority(),
nextresult, aElement);
if (!newmatch)
return NS_ERROR_OUT_OF_MEMORY;
@ -1177,7 +1177,7 @@ nsXULContentBuilder::CreateContainerContentsForQuerySet(nsIContent* aElement,
rv = DetermineMatchedRule(aElement, nextresult, aQuerySet,
&matchedrule, &ruleindex);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -1185,7 +1185,7 @@ nsXULContentBuilder::CreateContainerContentsForQuerySet(nsIContent* aElement,
rv = newmatch->RuleMatched(aQuerySet, matchedrule,
ruleindex, nextresult);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -1210,7 +1210,7 @@ nsXULContentBuilder::CreateContainerContentsForQuerySet(nsIContent* aElement,
if (removematch) {
newmatch->mNext = removematch->mNext;
nsTemplateMatch::Destroy(mPool, removematch, true);
nsTemplateMatch::Destroy(removematch, true);
}
else {
newmatch->mNext = existingmatch;

Просмотреть файл

@ -19,7 +19,6 @@
#include "nsCOMPtr.h"
#include "nsCRT.h"
#include "nsFixedSizeAllocator.h"
#include "nsIContent.h"
#include "nsIDOMElement.h"
#include "nsIDOMNode.h"
@ -112,12 +111,10 @@ nsXULTemplateBuilder::nsXULTemplateBuilder(void)
static PLDHashOperator
DestroyMatchList(nsISupports* aKey, nsTemplateMatch*& aMatch, void* aContext)
{
nsFixedSizeAllocator* pool = static_cast<nsFixedSizeAllocator *>(aContext);
// delete all the matches in the list
while (aMatch) {
nsTemplateMatch* next = aMatch->mNext;
nsTemplateMatch::Destroy(*pool, aMatch, true);
nsTemplateMatch::Destroy(aMatch, true);
aMatch = next;
}
@ -176,8 +173,7 @@ nsXULTemplateBuilder::InitGlobals()
if (!mMatchMap.IsInitialized())
mMatchMap.Init();
const size_t bucketsizes[] = { sizeof(nsTemplateMatch) };
return mPool.Init("nsXULTemplateBuilder", bucketsizes, 1, 256);
return NS_OK;
}
void
@ -190,7 +186,7 @@ nsXULTemplateBuilder::CleanUp(bool aIsFinal)
mQuerySets.Clear();
mMatchMap.Enumerate(DestroyMatchList, &mPool);
mMatchMap.Enumerate(DestroyMatchList, nullptr);
// Setting mQueryProcessor to null will close connections. This would be
// handled by the cycle collector, but we want to close them earlier.
@ -246,7 +242,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXULTemplateBuilder)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mListeners)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mQueryProcessor)
if (tmp->mMatchMap.IsInitialized()) {
tmp->mMatchMap.Enumerate(DestroyMatchList, &(tmp->mPool));
tmp->mMatchMap.Enumerate(DestroyMatchList, nullptr);
}
for (uint32_t i = 0; i < tmp->mQuerySets.Length(); ++i) {
nsTemplateQuerySet* qs = tmp->mQuerySets[i];
@ -778,7 +774,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
int32_t findpriority = aQuerySet->Priority();
newmatch = nsTemplateMatch::Create(mPool, findpriority,
newmatch = nsTemplateMatch::Create(findpriority,
aNewResult, aInsertionPoint);
if (!newmatch)
return NS_ERROR_OUT_OF_MEMORY;
@ -850,7 +846,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
rv = DetermineMatchedRule(aInsertionPoint, newmatch->mResult,
aQuerySet, &matchedrule, &ruleindex);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -859,7 +855,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
matchedrule, ruleindex,
newmatch->mResult);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -899,8 +895,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
rv = DetermineMatchedRule(aInsertionPoint, newmatch->mResult,
aQuerySet, &matchedrule, &ruleindex);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch,
false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -909,8 +904,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
matchedrule, ruleindex,
newmatch->mResult);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch,
false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -939,7 +933,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
rv = DetermineMatchedRule(aInsertionPoint, aNewResult,
aQuerySet, &matchedrule, &ruleindex);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -947,7 +941,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
rv = newmatch->RuleMatched(aQuerySet, matchedrule,
ruleindex, aNewResult);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -969,10 +963,10 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
if (mFlags & eLoggingEnabled)
OutputMatchToLog(aNewId, replacedmatch, false);
}
// remove a match that needs to be deleted.
if (replacedmatchtodelete)
nsTemplateMatch::Destroy(mPool, replacedmatchtodelete, true);
nsTemplateMatch::Destroy(replacedmatchtodelete, true);
// If the old match was active, the content for it needs to be removed.
// If the old match was not active, it shouldn't have had any content,
@ -984,7 +978,7 @@ nsXULTemplateBuilder::UpdateResultInContainer(nsIXULTemplateResult* aOldResult,
// delete the old match that was replaced
if (removedmatch)
nsTemplateMatch::Destroy(mPool, removedmatch, true);
nsTemplateMatch::Destroy(removedmatch, true);
if (mFlags & eLoggingEnabled && newmatch)
OutputMatchToLog(aNewId, newmatch, true);

Просмотреть файл

@ -18,7 +18,6 @@
#include "nsIRDFService.h"
#include "nsIXULTemplateBuilder.h"
#include "nsFixedSizeAllocator.h"
#include "nsCOMArray.h"
#include "nsTArray.h"
#include "nsDataHashtable.h"
@ -382,16 +381,6 @@ protected:
*/
nsDataHashtable<nsISupportsHashKey, nsTemplateMatch*> mMatchMap;
/**
* Fixed size allocator used to allocate matches
*/
nsFixedSizeAllocator mPool;
public:
nsFixedSizeAllocator& GetPool() { return mPool; }
protected:
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIRDFService* gRDFService;

Просмотреть файл

@ -1587,8 +1587,7 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
}
nsTemplateMatch *newmatch =
nsTemplateMatch::Create(mPool, aQuerySet->Priority(),
nextresult, nullptr);
nsTemplateMatch::Create(aQuerySet->Priority(), nextresult, nullptr);
if (!newmatch)
return NS_ERROR_OUT_OF_MEMORY;
@ -1601,7 +1600,7 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
nsCOMPtr<nsIRDFResource> parentid;
rv = GetResultResource(iter->mMatch->mResult, getter_AddRefs(parentid));
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -1614,7 +1613,7 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
if (cyclic) {
NS_WARNING("tree cannot handle cyclic graphs");
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
continue;
}
@ -1623,7 +1622,7 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
rv = DetermineMatchedRule(nullptr, nextresult, aQuerySet,
&matchedrule, &ruleindex);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -1631,7 +1630,7 @@ nsXULTreeBuilder::OpenSubtreeForQuerySet(nsTreeRows::Subtree* aSubtree,
rv = newmatch->RuleMatched(aQuerySet, matchedrule, ruleindex,
nextresult);
if (NS_FAILED(rv)) {
nsTemplateMatch::Destroy(mPool, newmatch, false);
nsTemplateMatch::Destroy(newmatch, false);
return rv;
}
@ -1712,7 +1711,7 @@ nsXULTreeBuilder::RemoveMatchesFor(nsTreeRows::Subtree& subtree)
if (mMatchMap.Get(id, &existingmatch)) {
while (existingmatch) {
nsTemplateMatch* nextmatch = existingmatch->mNext;
nsTemplateMatch::Destroy(mPool, existingmatch, true);
nsTemplateMatch::Destroy(existingmatch, true);
existingmatch = nextmatch;
}