Bug 847248 (part 8) - Remove nsFixedSizeAllocator from xbl/. r=bz.

--HG--
extra : rebase_source : 3e4675e525674e9fda53831676d8440ff55a49cb
This commit is contained in:
Nicholas Nethercote 2013-03-05 05:12:16 -08:00
parent 3329a77302
commit 20e250004b
2 changed files with 32 additions and 151 deletions

View File

@ -27,7 +27,6 @@
#include "nsXBLInsertionPoint.h"
#include "nsXBLPrototypeBinding.h"
#include "nsXBLContentSink.h"
#include "nsFixedSizeAllocator.h"
#include "xptinfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIDocumentObserver.h"
@ -81,38 +80,8 @@ class nsIIDKey : public nsHashKey {
class nsXBLAttributeEntry {
public:
nsIAtom* GetSrcAttribute() { return mSrcAttribute; }
nsIAtom* GetDstAttribute() { return mDstAttribute; }
int32_t GetDstNameSpace() { return mDstNameSpace; }
nsIContent* GetElement() { return mElement; }
nsXBLAttributeEntry* GetNext() { return mNext; }
void SetNext(nsXBLAttributeEntry* aEntry) { mNext = aEntry; }
static nsXBLAttributeEntry*
Create(nsIAtom* aSrcAtom, nsIAtom* aDstAtom, int32_t aDstNameSpace, nsIContent* aContent) {
void* place = nsXBLPrototypeBinding::kAttrPool->Alloc(sizeof(nsXBLAttributeEntry));
return place ? ::new (place) nsXBLAttributeEntry(aSrcAtom, aDstAtom, aDstNameSpace,
aContent) : nullptr;
}
static void
Destroy(nsXBLAttributeEntry* aSelf) {
aSelf->~nsXBLAttributeEntry();
nsXBLPrototypeBinding::kAttrPool->Free(aSelf, sizeof(*aSelf));
}
protected:
nsIContent* mElement;
nsCOMPtr<nsIAtom> mSrcAttribute;
nsCOMPtr<nsIAtom> mDstAttribute;
int32_t mDstNameSpace;
nsXBLAttributeEntry* mNext;
nsXBLAttributeEntry(nsIAtom* aSrcAtom, nsIAtom* aDstAtom, int32_t aDstNameSpace,
nsIContent* aContent)
nsXBLAttributeEntry(nsIAtom* aSrcAtom, nsIAtom* aDstAtom,
int32_t aDstNameSpace, nsIContent* aContent)
: mElement(aContent),
mSrcAttribute(aSrcAtom),
mDstAttribute(aDstAtom),
@ -123,11 +92,22 @@ protected:
NS_CONTENT_DELETE_LIST_MEMBER(nsXBLAttributeEntry, this, mNext);
}
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) {}
nsIAtom* GetSrcAttribute() { return mSrcAttribute; }
nsIAtom* GetDstAttribute() { return mDstAttribute; }
int32_t GetDstNameSpace() { return mDstNameSpace; }
nsIContent* GetElement() { return mElement; }
nsXBLAttributeEntry* GetNext() { return mNext; }
void SetNext(nsXBLAttributeEntry* aEntry) { mNext = aEntry; }
protected:
nsIContent* mElement;
nsCOMPtr<nsIAtom> mSrcAttribute;
nsCOMPtr<nsIAtom> mDstAttribute;
int32_t mDstNameSpace;
nsXBLAttributeEntry* mNext;
};
// nsXBLInsertionPointEntry and helpers. This class stores all the necessary
@ -137,6 +117,11 @@ private:
class nsXBLInsertionPointEntry {
public:
nsXBLInsertionPointEntry(nsIContent* aParent)
: mInsertionParent(aParent),
mInsertionIndex(0)
{}
~nsXBLInsertionPointEntry() {
if (mDefaultContent) {
nsAutoScriptBlocker scriptBlocker;
@ -144,7 +129,7 @@ public:
// document, and we own and manage it. Unhook it here, since we're going
// away.
mDefaultContent->UnbindFromTree();
}
}
}
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(nsXBLInsertionPointEntry)
@ -156,78 +141,14 @@ public:
nsIContent* GetDefaultContent() { return mDefaultContent; }
void SetDefaultContent(nsIContent* aChildren) { mDefaultContent = aChildren; }
// We keep kPool alive as long as there is at least either a
// nsXBLPrototypeBinding or a nsXBLInsertionPointEntry alive.
// nsXBLPrototypeBinding has its own global refcount so it only adds 1 to
// nsXBLInsertionPointEntry::gRefCnt as long as there's at least one
// nsXBLPrototypeBinding alive.
static void InitPool(int32_t aInitialSize)
{
if (++gRefCnt == 1) {
kPool = new nsFixedSizeAllocator();
if (kPool) {
static const size_t kBucketSizes[] = {
sizeof(nsXBLInsertionPointEntry)
};
kPool->Init("XBL Insertion Point Entries", kBucketSizes,
ArrayLength(kBucketSizes), aInitialSize);
}
}
}
static bool PoolInited()
{
return kPool != nullptr;
}
static void ReleasePool()
{
if (--gRefCnt == 0) {
delete kPool;
}
}
static nsXBLInsertionPointEntry*
Create(nsIContent* aParent) {
void* place = kPool->Alloc(sizeof(nsXBLInsertionPointEntry));
if (!place) {
return nullptr;
}
++gRefCnt;
return ::new (place) nsXBLInsertionPointEntry(aParent);
}
static void
Destroy(nsXBLInsertionPointEntry* aSelf) {
aSelf->~nsXBLInsertionPointEntry();
kPool->Free(aSelf, sizeof(*aSelf));
nsXBLInsertionPointEntry::ReleasePool();
}
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(nsXBLInsertionPointEntry)
protected:
nsCOMPtr<nsIContent> mInsertionParent;
nsCOMPtr<nsIContent> mDefaultContent;
uint32_t mInsertionIndex;
nsXBLInsertionPointEntry(nsIContent* aParent)
: mInsertionParent(aParent),
mInsertionIndex(0) { }
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) {}
static nsFixedSizeAllocator* kPool;
static uint32_t gRefCnt;
};
uint32_t nsXBLInsertionPointEntry::gRefCnt = 0;
nsFixedSizeAllocator* nsXBLInsertionPointEntry::kPool;
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsXBLInsertionPointEntry)
NS_IMPL_CYCLE_COLLECTION_UNLINK(mInsertionParent)
if (tmp->mDefaultContent) {
@ -248,29 +169,13 @@ NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(nsXBLInsertionPointEntry, Release)
// =============================================================================
// Static initialization
uint32_t nsXBLPrototypeBinding::gRefCnt = 0;
nsFixedSizeAllocator* nsXBLPrototypeBinding::kAttrPool;
static const int32_t kNumElements = 128;
static const size_t kAttrBucketSizes[] = {
sizeof(nsXBLAttributeEntry)
};
static const int32_t kAttrNumBuckets = sizeof(kAttrBucketSizes)/sizeof(size_t);
static const int32_t kAttrInitialSize = sizeof(nsXBLAttributeEntry) * kNumElements;
static const int32_t kInsInitialSize = sizeof(nsXBLInsertionPointEntry) * kNumElements;
// Implementation /////////////////////////////////////////////////////////////////
// Constructors/Destructors
nsXBLPrototypeBinding::nsXBLPrototypeBinding()
: mImplementation(nullptr),
mBaseBinding(nullptr),
mInheritStyle(true),
mInheritStyle(true),
mCheckedBaseProto(false),
mKeyHandlersRegistered(false),
mChromeOnlyContent(false),
@ -281,15 +186,6 @@ nsXBLPrototypeBinding::nsXBLPrototypeBinding()
mBaseNameSpaceID(kNameSpaceID_None)
{
MOZ_COUNT_CTOR(nsXBLPrototypeBinding);
gRefCnt++;
if (gRefCnt == 1) {
kAttrPool = new nsFixedSizeAllocator();
if (kAttrPool) {
kAttrPool->Init("XBL Attribute Entries", kAttrBucketSizes, kAttrNumBuckets, kAttrInitialSize);
}
nsXBLInsertionPointEntry::InitPool(kInsInitialSize);
}
}
nsresult
@ -298,10 +194,6 @@ nsXBLPrototypeBinding::Init(const nsACString& aID,
nsIContent* aElement,
bool aFirstBinding)
{
if (!kAttrPool || !nsXBLInsertionPointEntry::PoolInited()) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = aInfo->DocumentURI()->Clone(getter_AddRefs(mBindingURI));
NS_ENSURE_SUCCESS(rv, rv);
@ -403,11 +295,6 @@ nsXBLPrototypeBinding::~nsXBLPrototypeBinding(void)
delete mInsertionPointTable;
delete mInterfaceTable;
delete mImplementation;
gRefCnt--;
if (gRefCnt == 0) {
delete kAttrPool;
nsXBLInsertionPointEntry::ReleasePool();
}
MOZ_COUNT_DTOR(nsXBLPrototypeBinding);
}
@ -1071,7 +958,7 @@ nsXBLPrototypeBinding::GetStyleSheets()
static bool
DeleteAttributeEntry(nsHashKey* aKey, void* aData, void* aClosure)
{
nsXBLAttributeEntry::Destroy(static_cast<nsXBLAttributeEntry*>(aData));
delete static_cast<nsXBLAttributeEntry*>(aData);
return true;
}
@ -1106,9 +993,9 @@ nsXBLPrototypeBinding::AddToAttributeTable(int32_t aSourceNamespaceID, nsIAtom*
nullptr, 4);
mAttributeTable->Put(&nskey, attributesNS);
}
nsXBLAttributeEntry* xblAttr =
nsXBLAttributeEntry::Create(aSourceTag, aDestTag, aDestNamespaceID, aContent);
new nsXBLAttributeEntry(aSourceTag, aDestTag, aDestNamespaceID, aContent);
nsISupportsKey key(aSourceTag);
nsXBLAttributeEntry* entry = static_cast<nsXBLAttributeEntry*>
@ -1230,10 +1117,10 @@ nsXBLPrototypeBinding::ConstructInsertionTable(nsIContent* aContent)
int32_t i;
for (i = 0; i < count; i++) {
nsIContent* child = childrenElements[i];
nsCOMPtr<nsIContent> parent = child->GetParent();
nsCOMPtr<nsIContent> parent = child->GetParent();
// Create an XBL insertion point entry.
nsXBLInsertionPointEntry* xblIns = nsXBLInsertionPointEntry::Create(parent);
nsXBLInsertionPointEntry* xblIns = new nsXBLInsertionPointEntry(parent);
nsAutoString includes;
child->GetAttr(kNameSpaceID_None, nsGkAtoms::includes, includes);
@ -1892,7 +1779,7 @@ nsXBLPrototypeBinding::ReadContentNode(nsIObjectInputStream* aStream,
namespaceID, nsIDOMNode::ATTRIBUTE_NODE);
attrs[i].mName.SetTo(ni);
}
rv = prototype->SetAttrAt(i, val, documentURI);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1962,7 +1849,7 @@ nsXBLPrototypeBinding::ReadContentNode(nsIObjectInputStream* aStream,
NS_ENSURE_SUCCESS(rv, rv);
while (insertionPointIndex != XBLBinding_Serialize_NoMoreInsertionPoints) {
nsRefPtr<nsXBLInsertionPointEntry> xblIns =
nsXBLInsertionPointEntry::Create(content);
new nsXBLInsertionPointEntry(content);
xblIns->SetInsertionIndex(insertionPointIndex);
// If the insertion point has default content, read it.

View File

@ -23,7 +23,6 @@ class nsIAtom;
class nsIDocument;
class nsIScriptContext;
class nsSupportsHashtable;
class nsFixedSizeAllocator;
class nsXBLProtoImplField;
class nsXBLBinding;
class nsCSSStyleSheet;
@ -284,11 +283,6 @@ public:
void UnlinkJSObjects();
void Trace(TraceCallback aCallback, void *aClosure) const;
// Static members
static uint32_t gRefCnt;
static nsFixedSizeAllocator* kAttrPool;
// Internal member functions.
// XXXbz GetImmediateChild needs to be public to be called by SetAttrs,
// InstantiateInsertionPoints, etc; those should probably be a class static