зеркало из https://github.com/mozilla/pjs.git
Bug 414894 - Remove content arena. r=smaug, sr=sicking, a=schrep
This commit is contained in:
Родитель
968adc1363
Коммит
281f7d943c
|
@ -59,7 +59,6 @@ class nsIMutationObserver;
|
|||
class nsChildContentList;
|
||||
class nsNodeWeakReference;
|
||||
class nsNodeSupportsWeakRefTearoff;
|
||||
class nsDOMNodeAllocator;
|
||||
|
||||
enum {
|
||||
// This bit will be set if the node doesn't have nsSlots
|
||||
|
@ -123,8 +122,8 @@ inline nsINode* NODE_FROM(C& aContent, D& aDocument)
|
|||
|
||||
// IID for the nsINode interface
|
||||
#define NS_INODE_IID \
|
||||
{ 0xcf677826, 0xd7f1, 0x4ec5, \
|
||||
{ 0xbf, 0x3a, 0xd4, 0x18, 0x11, 0xac, 0x58, 0x46 } }
|
||||
{ 0xd1c2e967, 0x854a, 0x436b, \
|
||||
{ 0xbf, 0xa5, 0xf6, 0xa4, 0x9a, 0x97, 0x46, 0x74 } }
|
||||
|
||||
/**
|
||||
* An internal interface that abstracts some DOMNode-related parts that both
|
||||
|
@ -573,11 +572,6 @@ public:
|
|||
* Weak reference to this node
|
||||
*/
|
||||
nsNodeWeakReference* mWeakReference;
|
||||
|
||||
void* operator new(size_t aSize, nsDOMNodeAllocator* aAllocator);
|
||||
void operator delete(void* aPtr, size_t aSize);
|
||||
private:
|
||||
void* operator new(size_t aSize) CPP_THROW_NEW;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -636,13 +630,6 @@ private:
|
|||
#endif
|
||||
}
|
||||
|
||||
// Returns nsnull only when called on an nsIDocument object.
|
||||
virtual nsDOMNodeAllocator* GetAllocator() = 0;
|
||||
|
||||
void* operator new(size_t aSize, nsINodeInfo* aNodeInfo);
|
||||
void operator delete(void* aPtr, size_t aSize);
|
||||
private:
|
||||
void* operator new(size_t aSize) CPP_THROW_NEW;
|
||||
protected:
|
||||
|
||||
// Override this function to create a custom slots class.
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
%import-idl "nsIDOMXPathEvaluator.idl"
|
||||
|
||||
%pseudo-iid nsIContent fba9aa39-016e-4d5d-ab62-22a1b84a3c7b
|
||||
%pseudo-iid nsINode cf677826-d7f1-4ec5-bf3a-d41811ac5846
|
||||
%pseudo-iid nsINode d1c2e967-854a-436b-bfa5-f6a49a974674
|
||||
%pseudo-iid nsPIDOMEventTarget 44a6597b-9fc3-4a8d-b7a4-d9009abf9d15
|
||||
%pseudo-iid nsIDocument 626d86d2-615f-4a12-94d8-e3db3a298372
|
||||
%pseudo-iid nsIScriptObjectPrincipal 3eedba38-8d22-41e1-817a-0e43e165b664
|
||||
|
|
|
@ -119,28 +119,20 @@ GetIndexFromCache(const nsAttrAndChildArray* aArray)
|
|||
#define NS_IMPL_EXTRA_SIZE \
|
||||
((sizeof(Impl) - sizeof(mImpl->mBuffer)) / sizeof(void*))
|
||||
|
||||
nsAttrAndChildArray::nsAttrAndChildArray(nsDOMNodeAllocator* aAllocator)
|
||||
: mImpl(nsnull), mAllocator(aAllocator)
|
||||
nsAttrAndChildArray::nsAttrAndChildArray()
|
||||
: mImpl(nsnull)
|
||||
{
|
||||
NS_IF_ADDREF(mAllocator);
|
||||
}
|
||||
|
||||
nsAttrAndChildArray::~nsAttrAndChildArray()
|
||||
{
|
||||
if (mImpl) {
|
||||
Clear();
|
||||
mAllocator->Free((mImpl->mBufferSize + NS_IMPL_EXTRA_SIZE) * sizeof(void*),
|
||||
mImpl);
|
||||
if (!mImpl) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mAllocator);
|
||||
}
|
||||
Clear();
|
||||
|
||||
void
|
||||
nsAttrAndChildArray::SetAllocator(nsDOMNodeAllocator* aAllocator)
|
||||
{
|
||||
NS_ASSERTION(!mAllocator, "Allocator already set!");
|
||||
NS_ADDREF(mAllocator = aAllocator);
|
||||
PR_Free(mImpl);
|
||||
}
|
||||
|
||||
nsIContent*
|
||||
|
@ -601,6 +593,39 @@ nsAttrAndChildArray::WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrAndChildArray::Compact()
|
||||
{
|
||||
if (!mImpl) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First compress away empty attrslots
|
||||
PRUint32 slotCount = AttrSlotCount();
|
||||
PRUint32 attrCount = NonMappedAttrCount();
|
||||
PRUint32 childCount = ChildCount();
|
||||
|
||||
if (attrCount < slotCount) {
|
||||
memmove(mImpl->mBuffer + attrCount * ATTRSIZE,
|
||||
mImpl->mBuffer + slotCount * ATTRSIZE,
|
||||
childCount * sizeof(nsIContent*));
|
||||
SetAttrSlotCount(attrCount);
|
||||
}
|
||||
|
||||
// Then resize or free buffer
|
||||
PRUint32 newSize = attrCount * ATTRSIZE + childCount;
|
||||
if (!newSize && !mImpl->mMappedAttrs) {
|
||||
PR_Free(mImpl);
|
||||
mImpl = nsnull;
|
||||
}
|
||||
else if (newSize < mImpl->mBufferSize) {
|
||||
mImpl = static_cast<Impl*>(PR_Realloc(mImpl, (newSize + NS_IMPL_EXTRA_SIZE) * sizeof(nsIContent*)));
|
||||
NS_ASSERTION(mImpl, "failed to reallocate to smaller buffer");
|
||||
|
||||
mImpl->mBufferSize = newSize;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsAttrAndChildArray::Clear()
|
||||
{
|
||||
|
@ -730,17 +755,16 @@ nsAttrAndChildArray::GrowBy(PRUint32 aGrowSize)
|
|||
size = PR_BIT(PR_CeilingLog2(minSize));
|
||||
}
|
||||
|
||||
Impl* newImpl = static_cast<Impl*>(mAllocator->Alloc(size * sizeof(void*)));
|
||||
Impl* newImpl = static_cast<Impl*>
|
||||
(mImpl ? PR_Realloc(mImpl, size * sizeof(void*)) :
|
||||
PR_Malloc(size * sizeof(void*)));
|
||||
NS_ENSURE_TRUE(newImpl, PR_FALSE);
|
||||
|
||||
Impl* oldImpl = mImpl;
|
||||
mImpl = newImpl;
|
||||
if (oldImpl) {
|
||||
PRUint32 oldSize =
|
||||
(oldImpl->mBufferSize + NS_IMPL_EXTRA_SIZE) * sizeof(void*);
|
||||
memcpy(newImpl, oldImpl, oldSize);
|
||||
mAllocator->Free(oldSize, oldImpl);
|
||||
} else {
|
||||
// Set initial counts if we didn't have a buffer before
|
||||
|
||||
// Set initial counts if we didn't have a buffer before
|
||||
if (!oldImpl) {
|
||||
mImpl->mMappedAttrs = nsnull;
|
||||
SetAttrSlotAndChildCount(0, 0);
|
||||
}
|
||||
|
|
|
@ -75,10 +75,8 @@ class nsMappedAttributeElement;
|
|||
class nsAttrAndChildArray
|
||||
{
|
||||
public:
|
||||
nsAttrAndChildArray(nsDOMNodeAllocator* aAllocator);
|
||||
nsAttrAndChildArray();
|
||||
~nsAttrAndChildArray();
|
||||
void SetAllocator(nsDOMNodeAllocator* aAllocator);
|
||||
nsDOMNodeAllocator* Allocator() { return mAllocator; }
|
||||
|
||||
PRUint32 ChildCount() const
|
||||
{
|
||||
|
@ -125,6 +123,8 @@ public:
|
|||
nsresult SetMappedAttrStyleSheet(nsHTMLStyleSheet* aSheet);
|
||||
void WalkMappedAttributeStyleRules(nsRuleWalker* aRuleWalker);
|
||||
|
||||
void Compact();
|
||||
|
||||
private:
|
||||
nsAttrAndChildArray(const nsAttrAndChildArray& aOther); // Not to be implemented
|
||||
nsAttrAndChildArray& operator=(const nsAttrAndChildArray& aOther); // Not to be implemented
|
||||
|
@ -186,8 +186,7 @@ private:
|
|||
void* mBuffer[1];
|
||||
};
|
||||
|
||||
Impl* mImpl;
|
||||
nsDOMNodeAllocator* mAllocator;
|
||||
Impl* mImpl;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -88,7 +88,7 @@ NS_NewCommentNode(nsIContent** aInstancePtrResult,
|
|||
nsCOMPtr<nsINodeInfo> ni = aNodeInfoManager->GetCommentNodeInfo();
|
||||
NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsCommentNode *instance = new (ni) nsCommentNode(ni);
|
||||
nsCommentNode *instance = new nsCommentNode(ni);
|
||||
if (!instance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ nsCommentNode::GetNodeType(PRUint16* aNodeType)
|
|||
nsGenericDOMDataNode*
|
||||
nsCommentNode::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
|
||||
{
|
||||
nsCommentNode *it = new (aNodeInfo) nsCommentNode(aNodeInfo);
|
||||
nsCommentNode *it = new nsCommentNode(aNodeInfo);
|
||||
if (it && aCloneText) {
|
||||
it->mText = mText;
|
||||
}
|
||||
|
|
|
@ -64,9 +64,7 @@ PRBool nsDOMAttribute::sInitialized;
|
|||
nsDOMAttribute::nsDOMAttribute(nsDOMAttributeMap *aAttrMap,
|
||||
nsINodeInfo *aNodeInfo,
|
||||
const nsAString &aValue)
|
||||
: nsIAttribute(aAttrMap, aNodeInfo),
|
||||
mAllocator(aNodeInfo->NodeInfoManager()->NodeAllocator()),
|
||||
mValue(aValue)
|
||||
: nsIAttribute(aAttrMap, aNodeInfo), mValue(aValue)
|
||||
{
|
||||
NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!");
|
||||
|
||||
|
@ -374,7 +372,7 @@ nsDOMAttribute::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|||
nsAutoString value;
|
||||
const_cast<nsDOMAttribute*>(this)->GetValue(value);
|
||||
|
||||
*aResult = new (aNodeInfo) nsDOMAttribute(nsnull, aNodeInfo, value);
|
||||
*aResult = new nsDOMAttribute(nsnull, aNodeInfo, value);
|
||||
if (!*aResult) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,6 @@ public:
|
|||
const nsIID& aIID);
|
||||
virtual nsresult GetSystemEventGroup(nsIDOMEventGroup** aGroup);
|
||||
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
||||
virtual nsDOMNodeAllocator* GetAllocator() { return mAllocator; }
|
||||
|
||||
static void Initialize();
|
||||
static void Shutdown();
|
||||
|
@ -121,7 +120,6 @@ protected:
|
|||
private:
|
||||
nsresult EnsureChildState(PRBool aSetText, PRBool &aHasChild) const;
|
||||
|
||||
nsDOMNodeAllocator* mAllocator;
|
||||
nsString mValue;
|
||||
// XXX For now, there's only a single child - a text
|
||||
// element representing the value
|
||||
|
|
|
@ -179,8 +179,8 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo,
|
|||
// the attribute node.
|
||||
mContent->GetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), value);
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> newAttr =
|
||||
new (aNodeInfo) nsDOMAttribute(aRemove ? nsnull : this, aNodeInfo, value);
|
||||
nsCOMPtr<nsIDOMNode> newAttr = new nsDOMAttribute(aRemove ? nsnull : this,
|
||||
aNodeInfo, value);
|
||||
if (!newAttr) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -89,8 +89,8 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType,
|
|||
kNameSpaceID_None, getter_AddRefs(ni));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
*aDocType = new (ni) nsDOMDocumentType(ni, aName, aEntities, aNotations,
|
||||
aPublicId, aSystemId, aInternalSubset);
|
||||
*aDocType = new nsDOMDocumentType(ni, aName, aEntities, aNotations,
|
||||
aPublicId, aSystemId, aInternalSubset);
|
||||
if (!*aDocType) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -235,9 +235,8 @@ nsDOMDocumentType::GetNodeType(PRUint16* aNodeType)
|
|||
nsGenericDOMDataNode*
|
||||
nsDOMDocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
|
||||
{
|
||||
return new (aNodeInfo) nsDOMDocumentType(aNodeInfo, mName, mEntities,
|
||||
mNotations, mPublicId, mSystemId,
|
||||
mInternalSubset);
|
||||
return new nsDOMDocumentType(aNodeInfo, mName, mEntities, mNotations,
|
||||
mPublicId, mSystemId, mInternalSubset);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -768,7 +768,6 @@ nsDOMImplementation::Init(nsIURI* aDocumentURI, nsIURI* aBaseURI,
|
|||
|
||||
nsDocument::nsDocument(const char* aContentType)
|
||||
: nsIDocument(),
|
||||
mChildren(nsnull),
|
||||
mVisible(PR_TRUE)
|
||||
{
|
||||
mContentType = aContentType;
|
||||
|
@ -1055,19 +1054,6 @@ nsDocument::Init()
|
|||
NS_ENSURE_TRUE(bindingManager, NS_ERROR_OUT_OF_MEMORY);
|
||||
NS_ADDREF(mBindingManager = bindingManager);
|
||||
|
||||
mNodeInfoManager = new nsNodeInfoManager();
|
||||
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(mNodeInfoManager);
|
||||
|
||||
nsresult rv = mNodeInfoManager->Init(this);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mChildren.SetAllocator(mNodeInfoManager->NodeAllocator());
|
||||
|
||||
mNodeInfo = mNodeInfoManager->GetDocumentNodeInfo();
|
||||
NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
nsINode::nsSlots* slots = GetSlots();
|
||||
NS_ENSURE_TRUE(slots,NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
|
@ -1088,6 +1074,17 @@ nsDocument::Init()
|
|||
mCSSLoader->SetCaseSensitive(PR_TRUE);
|
||||
mCSSLoader->SetCompatibilityMode(eCompatibility_FullStandards);
|
||||
|
||||
mNodeInfoManager = new nsNodeInfoManager();
|
||||
NS_ENSURE_TRUE(mNodeInfoManager, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(mNodeInfoManager);
|
||||
|
||||
nsresult rv = mNodeInfoManager->Init(this);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
mNodeInfo = mNodeInfoManager->GetDocumentNodeInfo();
|
||||
NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ASSERTION(GetOwnerDoc() == this, "Our nodeinfo is busted!");
|
||||
|
||||
mScriptLoader = new nsScriptLoader(this);
|
||||
|
@ -1096,13 +1093,6 @@ nsDocument::Init()
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsINode::nsSlots*
|
||||
nsDocument::CreateSlots()
|
||||
{
|
||||
return
|
||||
new (mNodeInfo->NodeInfoManager()->NodeAllocator()) nsSlots(mFlagsOrSlots);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::AddXMLEventsContent(nsIContent *aXMLEventsElement)
|
||||
{
|
||||
|
@ -3094,7 +3084,7 @@ nsDocument::CreateAttribute(const nsAString& aName,
|
|||
getter_AddRefs(nodeInfo));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
attribute = new (nodeInfo) nsDOMAttribute(nsnull, nodeInfo, value);
|
||||
attribute = new nsDOMAttribute(nsnull, nodeInfo, value);
|
||||
NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return CallQueryInterface(attribute, aReturn);
|
||||
|
@ -3116,8 +3106,7 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsAutoString value;
|
||||
nsDOMAttribute* attribute =
|
||||
new (nodeInfo) nsDOMAttribute(nsnull, nodeInfo, value);
|
||||
nsDOMAttribute* attribute = new nsDOMAttribute(nsnull, nodeInfo, value);
|
||||
NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
return CallQueryInterface(attribute, aResult);
|
||||
|
|
|
@ -536,7 +536,6 @@ public:
|
|||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
virtual nsDOMNodeAllocator* GetAllocator() { return nsnull; }
|
||||
|
||||
// nsIRadioGroupContainer
|
||||
NS_IMETHOD WalkRadioGroup(const nsAString& aName,
|
||||
|
@ -659,7 +658,6 @@ public:
|
|||
const nsAString& aClasses,
|
||||
nsIDOMNodeList** aReturn);
|
||||
protected:
|
||||
virtual nsINode::nsSlots* CreateSlots();
|
||||
|
||||
/**
|
||||
* Check that aId is not empty and log a message to the console
|
||||
|
|
|
@ -171,7 +171,7 @@ NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
|
|||
getter_AddRefs(nodeInfo));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsDocumentFragment *it = new (nodeInfo) nsDocumentFragment(nodeInfo);
|
||||
nsDocumentFragment *it = new nsDocumentFragment(nodeInfo);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ NS_NewGenConImageContent(nsIContent** aResult, nsINodeInfo* aNodeInfo,
|
|||
imgIRequest* aImageRequest)
|
||||
{
|
||||
NS_PRECONDITION(aImageRequest, "Must have request!");
|
||||
nsGenConImageContent *it = new (aNodeInfo) nsGenConImageContent(aNodeInfo);
|
||||
nsGenConImageContent *it = new nsGenConImageContent(aNodeInfo);
|
||||
if (!it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(*aResult = it);
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
#include "prprf.h"
|
||||
|
||||
nsGenericDOMDataNode::nsGenericDOMDataNode(nsINodeInfo *aNodeInfo)
|
||||
: nsIContent(aNodeInfo), mText(aNodeInfo->NodeInfoManager()->NodeAllocator())
|
||||
: nsIContent(aNodeInfo)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -864,7 +864,7 @@ nsGenericDOMDataNode::IsLink(nsIURI** aURI) const
|
|||
nsINode::nsSlots*
|
||||
nsGenericDOMDataNode::CreateSlots()
|
||||
{
|
||||
return new (GetAllocator()) nsDataSlots(mFlagsOrSlots);
|
||||
return new nsDataSlots(mFlagsOrSlots);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -187,7 +187,6 @@ public:
|
|||
virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener,
|
||||
const nsIID& aIID);
|
||||
virtual nsresult GetSystemEventGroup(nsIDOMEventGroup** aGroup);
|
||||
virtual nsDOMNodeAllocator* GetAllocator() { return mText.Allocator(); }
|
||||
|
||||
// Implementation for nsIContent
|
||||
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
||||
|
|
|
@ -171,44 +171,8 @@ nsINode::nsSlots::~nsSlots()
|
|||
}
|
||||
}
|
||||
|
||||
void*
|
||||
nsINode::nsSlots::operator new(size_t aSize, nsDOMNodeAllocator* aAllocator)
|
||||
{
|
||||
void* result = aAllocator->Alloc(aSize);
|
||||
if (result) {
|
||||
NS_ADDREF(aAllocator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsINode::nsSlots::operator delete(void* aPtr, size_t aSize)
|
||||
{
|
||||
size_t* szPtr = static_cast<size_t*>(aPtr);
|
||||
*szPtr = aSize;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void*
|
||||
nsINode::operator new(size_t aSize, nsINodeInfo* aNodeInfo)
|
||||
{
|
||||
nsDOMNodeAllocator* allocator =
|
||||
aNodeInfo->NodeInfoManager()->NodeAllocator();
|
||||
void* result = allocator->Alloc(aSize);
|
||||
if (result) {
|
||||
NS_ADDREF(allocator);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsINode::operator delete(void* aPtr, size_t aSize)
|
||||
{
|
||||
size_t* szPtr = static_cast<size_t*>(aPtr);
|
||||
*szPtr = aSize;
|
||||
}
|
||||
|
||||
nsINode::~nsINode()
|
||||
{
|
||||
NS_ASSERTION(!HasSlots(), "nsNodeUtils::LastRelease was not called?");
|
||||
|
@ -312,7 +276,7 @@ nsGenericElement::GetSystemEventGroup(nsIDOMEventGroup** aGroup)
|
|||
nsINode::nsSlots*
|
||||
nsINode::CreateSlots()
|
||||
{
|
||||
return new (GetAllocator()) nsSlots(mFlagsOrSlots);
|
||||
return new nsSlots(mFlagsOrSlots);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1158,8 +1122,7 @@ nsGenericElement::nsDOMSlots::~nsDOMSlots()
|
|||
}
|
||||
|
||||
nsGenericElement::nsGenericElement(nsINodeInfo *aNodeInfo)
|
||||
: nsIContent(aNodeInfo),
|
||||
mAttrsAndChildren(aNodeInfo->NodeInfoManager()->NodeAllocator())
|
||||
: nsIContent(aNodeInfo)
|
||||
{
|
||||
// Set the default scriptID to JS - but skip SetScriptTypeID as it
|
||||
// does extra work we know isn't necessary here...
|
||||
|
@ -4218,7 +4181,7 @@ nsGenericElement::IndexOf(nsINode* aPossibleChild) const
|
|||
nsINode::nsSlots*
|
||||
nsGenericElement::CreateSlots()
|
||||
{
|
||||
return new (GetAllocator()) nsDOMSlots(mFlagsOrSlots);
|
||||
return new nsDOMSlots(mFlagsOrSlots);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
|
|
@ -376,10 +376,6 @@ public:
|
|||
virtual nsresult RemoveEventListenerByIID(nsIDOMEventListener *aListener,
|
||||
const nsIID& aIID);
|
||||
virtual nsresult GetSystemEventGroup(nsIDOMEventGroup** aGroup);
|
||||
virtual nsDOMNodeAllocator* GetAllocator()
|
||||
{
|
||||
return mAttrsAndChildren.Allocator();
|
||||
}
|
||||
|
||||
// nsIContent interface methods
|
||||
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
||||
|
@ -1014,7 +1010,7 @@ _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const \
|
|||
{ \
|
||||
*aResult = nsnull; \
|
||||
\
|
||||
_elementName *it = new (aNodeInfo) _elementName(aNodeInfo); \
|
||||
_elementName *it = new _elementName(aNodeInfo); \
|
||||
if (!it) { \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
} \
|
||||
|
@ -1034,7 +1030,7 @@ _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const \
|
|||
{ \
|
||||
*aResult = nsnull; \
|
||||
\
|
||||
_elementName *it = new (aNodeInfo) _elementName(aNodeInfo); \
|
||||
_elementName *it = new _elementName(aNodeInfo); \
|
||||
if (!it) { \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
} \
|
||||
|
|
|
@ -51,175 +51,8 @@
|
|||
#include "nsReadableUtils.h"
|
||||
#include "nsGkAtoms.h"
|
||||
#include "nsComponentManagerUtils.h"
|
||||
#include "prbit.h"
|
||||
#include "plarena.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsLayoutStatics.h"
|
||||
|
||||
#define NS_SMALL_NODE_ARENA_SIZE \
|
||||
(512 * (sizeof(void*)/4))
|
||||
|
||||
#define NS_LARGE_NODE_ARENA_SIZE \
|
||||
(4096 * (sizeof(void*)/4))
|
||||
|
||||
#define NS_MAX_NODE_RECYCLE_SIZE \
|
||||
(NS_NODE_RECYCLER_SIZE * sizeof(void*))
|
||||
|
||||
#ifdef DEBUG
|
||||
static PRUint32 gDOMNodeAllocators = 0;
|
||||
// Counts the number of non-freed allocations.
|
||||
static size_t gDOMNodeAllocations = 0;
|
||||
static PRUint32 gDOMNodeRecyclerCounters[NS_NODE_RECYCLER_SIZE];
|
||||
static PRUint32 gDOMNodeNormalAllocations = 0;
|
||||
class nsDOMNodeAllocatorTester
|
||||
{
|
||||
public:
|
||||
nsDOMNodeAllocatorTester()
|
||||
{
|
||||
memset(gDOMNodeRecyclerCounters, 0, sizeof(gDOMNodeRecyclerCounters));
|
||||
}
|
||||
~nsDOMNodeAllocatorTester()
|
||||
{
|
||||
#ifdef DEBUG_smaug
|
||||
for (PRInt32 i = 0 ; i < NS_NODE_RECYCLER_SIZE; ++i) {
|
||||
if (gDOMNodeRecyclerCounters[i]) {
|
||||
printf("DOMNodeAllocator, arena allocation: %u bytes %u times\n",
|
||||
static_cast<unsigned int>((i + 1) * sizeof(void*)),
|
||||
gDOMNodeRecyclerCounters[i]);
|
||||
}
|
||||
}
|
||||
if (gDOMNodeNormalAllocations) {
|
||||
printf("DOMNodeAllocator, normal allocations: %i times \n",
|
||||
gDOMNodeNormalAllocations);
|
||||
}
|
||||
#endif
|
||||
if (gDOMNodeAllocations != 0) {
|
||||
printf("nsDOMNodeAllocator leaked %u bytes \n",
|
||||
static_cast<unsigned int>(gDOMNodeAllocations));
|
||||
}
|
||||
}
|
||||
};
|
||||
nsDOMNodeAllocatorTester gDOMAllocatorTester;
|
||||
#endif
|
||||
|
||||
nsDOMNodeAllocator::~nsDOMNodeAllocator()
|
||||
{
|
||||
if (mSmallPool) {
|
||||
PL_FinishArenaPool(mSmallPool);
|
||||
delete mSmallPool;
|
||||
}
|
||||
if (mLargePool) {
|
||||
PL_FinishArenaPool(mLargePool);
|
||||
delete mLargePool;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
--gDOMNodeAllocators;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMNodeAllocator::Init()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
++gDOMNodeAllocators;
|
||||
#endif
|
||||
memset(mRecyclers, 0, sizeof(mRecyclers));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsrefcnt
|
||||
nsDOMNodeAllocator::Release()
|
||||
{
|
||||
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
||||
--mRefCnt;
|
||||
NS_LOG_RELEASE(this, mRefCnt, "nsDOMNodeAllocator");
|
||||
if (mRefCnt == 0) {
|
||||
mRefCnt = 1; /* stabilize */
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
void*
|
||||
nsDOMNodeAllocator::Alloc(size_t aSize)
|
||||
{
|
||||
void* result = nsnull;
|
||||
|
||||
// Ensure we have correct alignment for pointers.
|
||||
aSize = aSize ? PR_ROUNDUP(aSize, sizeof(void*)) : sizeof(void*);
|
||||
// Check recyclers first
|
||||
if (aSize <= NS_MAX_NODE_RECYCLE_SIZE) {
|
||||
const PRInt32 index = (aSize / sizeof(void*)) - 1;
|
||||
result = mRecyclers[index];
|
||||
if (result) {
|
||||
// Need to move to the next object
|
||||
void* next = *((void**)result);
|
||||
mRecyclers[index] = next;
|
||||
}
|
||||
if (!result) {
|
||||
if ((mSmallPoolAllocated + aSize) > NS_LARGE_NODE_ARENA_SIZE) {
|
||||
if (!mLargePool) {
|
||||
mLargePool = new PLArenaPool();
|
||||
NS_ENSURE_TRUE(mLargePool, nsnull);
|
||||
PL_InitArenaPool(mLargePool, "nsDOMNodeAllocator-large",
|
||||
NS_LARGE_NODE_ARENA_SIZE, 0);
|
||||
}
|
||||
// Allocate a new chunk from the 'large' arena
|
||||
PL_ARENA_ALLOCATE(result, mLargePool, aSize);
|
||||
} else {
|
||||
if (!mSmallPool) {
|
||||
mSmallPool = new PLArenaPool();
|
||||
NS_ENSURE_TRUE(mSmallPool, nsnull);
|
||||
PL_InitArenaPool(mSmallPool, "nsDOMNodeAllocator-small",
|
||||
NS_SMALL_NODE_ARENA_SIZE, 0);
|
||||
}
|
||||
// Allocate a new chunk from the 'small' arena
|
||||
PL_ARENA_ALLOCATE(result, mSmallPool, aSize);
|
||||
if (result) {
|
||||
mSmallPoolAllocated += aSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
++gDOMNodeRecyclerCounters[index];
|
||||
#endif
|
||||
} else {
|
||||
result = nsMemory::Alloc(aSize);
|
||||
#ifdef DEBUG
|
||||
++gDOMNodeNormalAllocations;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
gDOMNodeAllocations += aSize;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMNodeAllocator::Free(size_t aSize, void* aPtr)
|
||||
{
|
||||
if (!aPtr) {
|
||||
return;
|
||||
}
|
||||
// Ensure we have correct alignment for pointers.
|
||||
aSize = aSize ? PR_ROUNDUP(aSize, sizeof(void*)) : sizeof(void*);
|
||||
// See if it's a size that we recycle
|
||||
if (aSize <= NS_MAX_NODE_RECYCLE_SIZE) {
|
||||
const PRInt32 index = (aSize / sizeof(void*)) - 1;
|
||||
void* currentTop = mRecyclers[index];
|
||||
mRecyclers[index] = aPtr;
|
||||
*((void**)aPtr) = currentTop;
|
||||
} else {
|
||||
nsMemory::Free(aPtr);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
gDOMNodeAllocations -= aSize;
|
||||
#endif
|
||||
}
|
||||
|
||||
PLHashNumber
|
||||
nsNodeInfoManager::GetNodeInfoInnerHashValue(const void *key)
|
||||
{
|
||||
|
@ -307,10 +140,6 @@ nsNodeInfoManager::Init(nsIDocument *aDocument)
|
|||
{
|
||||
NS_ENSURE_TRUE(mNodeInfoHash, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
mNodeAllocator = new nsDOMNodeAllocator();
|
||||
NS_ENSURE_TRUE(mNodeAllocator && NS_SUCCEEDED(mNodeAllocator->Init()),
|
||||
NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_PRECONDITION(!mPrincipal,
|
||||
"Being inited when we already have a principal?");
|
||||
nsresult rv = CallCreateInstance("@mozilla.org/nullprincipal;1",
|
||||
|
|
|
@ -44,7 +44,6 @@
|
|||
|
||||
#include "nsCOMPtr.h" // for already_AddRefed
|
||||
#include "plhash.h"
|
||||
#include "nsAutoPtr.h"
|
||||
|
||||
class nsIAtom;
|
||||
class nsIDocument;
|
||||
|
@ -58,42 +57,6 @@ class nsIDOMDocument;
|
|||
class nsAString;
|
||||
class nsIDOMNamedNodeMap;
|
||||
class nsXULPrototypeDocument;
|
||||
class nsNodeInfoManager;
|
||||
struct PLArenaPool;
|
||||
|
||||
// The size of mRecyclers array. The max size of recycled memory is
|
||||
// sizeof(void*) * NS_NODE_RECYCLER_SIZE.
|
||||
#define NS_NODE_RECYCLER_SIZE 64
|
||||
|
||||
class nsDOMNodeAllocator
|
||||
{
|
||||
public:
|
||||
nsDOMNodeAllocator()
|
||||
: mSmallPool(nsnull), mLargePool(nsnull), mSmallPoolAllocated(0) {}
|
||||
~nsDOMNodeAllocator();
|
||||
|
||||
nsrefcnt AddRef()
|
||||
{
|
||||
NS_ASSERTION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
||||
++mRefCnt;
|
||||
NS_LOG_ADDREF(this, mRefCnt, "nsDOMNodeAllocator", sizeof(*this));
|
||||
return mRefCnt;
|
||||
}
|
||||
nsrefcnt Release();
|
||||
|
||||
void* Alloc(size_t aSize);
|
||||
void Free(size_t aSize, void* aPtr);
|
||||
protected:
|
||||
friend class nsNodeInfoManager;
|
||||
nsresult Init();
|
||||
nsAutoRefCnt mRefCnt;
|
||||
PLArenaPool* mSmallPool;
|
||||
PLArenaPool* mLargePool;
|
||||
size_t mSmallPoolAllocated;
|
||||
// The recycler array points to recycled memory, where the size of
|
||||
// block is index*sizeof(void*), i.e., 0, 4, 8, 12, 16, ... or 0, 8, 16, ...
|
||||
void* mRecyclers[NS_NODE_RECYCLER_SIZE];
|
||||
};
|
||||
|
||||
class nsNodeInfoManager
|
||||
{
|
||||
|
@ -160,7 +123,6 @@ public:
|
|||
|
||||
void RemoveNodeInfo(nsNodeInfo *aNodeInfo);
|
||||
|
||||
nsDOMNodeAllocator* NodeAllocator() { return mNodeAllocator; }
|
||||
protected:
|
||||
friend class nsDocument;
|
||||
friend class nsXULPrototypeDocument;
|
||||
|
@ -196,8 +158,6 @@ private:
|
|||
nsINodeInfo *mTextNodeInfo; // WEAK to avoid circular ownership
|
||||
nsINodeInfo *mCommentNodeInfo; // WEAK to avoid circular ownership
|
||||
nsINodeInfo *mDocumentNodeInfo; // WEAK to avoid circular ownership
|
||||
|
||||
nsRefPtr<nsDOMNodeAllocator> mNodeAllocator;
|
||||
};
|
||||
|
||||
#endif /* nsNodeInfoManager_h___ */
|
||||
|
|
|
@ -188,7 +188,6 @@ void
|
|||
nsNodeUtils::LastRelease(nsINode* aNode)
|
||||
{
|
||||
nsINode::nsSlots* slots = aNode->GetExistingSlots();
|
||||
nsRefPtr<nsDOMNodeAllocator> allocator = aNode->GetAllocator();
|
||||
if (slots) {
|
||||
if (!slots->mMutationObservers.IsEmpty()) {
|
||||
NS_OBSERVER_ARRAY_NOTIFY_OBSERVERS(slots->mMutationObservers,
|
||||
|
@ -197,14 +196,7 @@ nsNodeUtils::LastRelease(nsINode* aNode)
|
|||
}
|
||||
|
||||
PtrBits flags = slots->mFlags | NODE_DOESNT_HAVE_SLOTS;
|
||||
delete slots; // Calls destructor and sets size to *slots.
|
||||
NS_ASSERTION(allocator || aNode->IsNodeOfType(nsINode::eDOCUMENT),
|
||||
"Should have allocator or document!");
|
||||
nsDOMNodeAllocator* slotsAllocator = allocator ?
|
||||
allocator.get() : aNode->mNodeInfo->NodeInfoManager()->NodeAllocator();
|
||||
size_t* sz = reinterpret_cast<size_t*>(slots);
|
||||
slotsAllocator->Free(*sz, static_cast<void*>(slots));
|
||||
NS_RELEASE(slotsAllocator);
|
||||
delete slots;
|
||||
aNode->mFlagsOrSlots = flags;
|
||||
}
|
||||
|
||||
|
@ -243,16 +235,7 @@ nsNodeUtils::LastRelease(nsINode* aNode)
|
|||
aNode->UnsetFlags(NODE_HAS_LISTENERMANAGER);
|
||||
}
|
||||
|
||||
if (aNode->IsNodeOfType(nsINode::eDOCUMENT)) {
|
||||
delete aNode;
|
||||
} else {
|
||||
NS_ASSERTION(allocator, "Should have allocator here!");
|
||||
delete aNode; // Calls destructor and sets size to *aNode.
|
||||
size_t* sz = reinterpret_cast<size_t*>(aNode);
|
||||
allocator->Free(*sz, static_cast<void*>(aNode));
|
||||
nsDOMNodeAllocator* tmpAlloc = allocator;
|
||||
NS_RELEASE(tmpAlloc);
|
||||
}
|
||||
delete aNode;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsBidiUtils.h"
|
||||
#include "nsUnicharUtils.h"
|
||||
#include "nsNodeInfoManager.h"
|
||||
|
||||
#define TEXTFRAG_WHITE_AFTER_NEWLINE 50
|
||||
#define TEXTFRAG_MAX_NEWLINES 7
|
||||
|
@ -102,27 +102,16 @@ nsTextFragment::Shutdown()
|
|||
}
|
||||
}
|
||||
|
||||
nsTextFragment::nsTextFragment(nsDOMNodeAllocator* aAllocator)
|
||||
: m1b(nsnull), mAllBits(0), mAllocator(aAllocator)
|
||||
{
|
||||
NS_ADDREF(mAllocator);
|
||||
NS_ASSERTION(sizeof(FragmentBits) == 4, "Bad field packing!");
|
||||
}
|
||||
|
||||
nsTextFragment::~nsTextFragment()
|
||||
{
|
||||
ReleaseText();
|
||||
NS_RELEASE(mAllocator);
|
||||
}
|
||||
|
||||
void
|
||||
nsTextFragment::ReleaseText()
|
||||
{
|
||||
if (mState.mLength && m1b && mState.mInHeap) {
|
||||
// m1b == m2b as far as memory is concerned
|
||||
mAllocator->Free(mState.mLength *
|
||||
(mState.mIs2b ? sizeof(PRUnichar) : sizeof(char)),
|
||||
m2b);
|
||||
nsMemory::Free(m2b); // m1b == m2b as far as nsMemory is concerned
|
||||
}
|
||||
|
||||
m1b = nsnull;
|
||||
|
@ -131,16 +120,6 @@ nsTextFragment::ReleaseText()
|
|||
mAllBits = 0;
|
||||
}
|
||||
|
||||
void*
|
||||
nsTextFragment::CloneMemory(const void* aPtr, PRSize aSize)
|
||||
{
|
||||
void* newPtr = mAllocator->Alloc(aSize);
|
||||
if (newPtr) {
|
||||
memcpy(newPtr, aPtr, aSize);
|
||||
}
|
||||
return newPtr;
|
||||
}
|
||||
|
||||
nsTextFragment&
|
||||
nsTextFragment::operator=(const nsTextFragment& aOther)
|
||||
{
|
||||
|
@ -151,11 +130,9 @@ nsTextFragment::operator=(const nsTextFragment& aOther)
|
|||
m1b = aOther.m1b; // This will work even if aOther is using m2b
|
||||
}
|
||||
else {
|
||||
m2b =
|
||||
static_cast<PRUnichar*>
|
||||
(CloneMemory(aOther.m2b, aOther.mState.mLength *
|
||||
(aOther.mState.mIs2b ?
|
||||
sizeof(PRUnichar) : sizeof(char))));
|
||||
m2b = static_cast<PRUnichar*>
|
||||
(nsMemory::Clone(aOther.m2b, aOther.mState.mLength *
|
||||
(aOther.mState.mIs2b ? sizeof(PRUnichar) : sizeof(char))));
|
||||
}
|
||||
|
||||
if (m1b) {
|
||||
|
@ -236,13 +213,14 @@ nsTextFragment::SetTo(const PRUnichar* aBuffer, PRInt32 aLength)
|
|||
|
||||
if (need2) {
|
||||
// Use ucs2 storage because we have to
|
||||
m2b = (PRUnichar *)CloneMemory(aBuffer, aLength * sizeof(PRUnichar));
|
||||
m2b = (PRUnichar *)nsMemory::Clone(aBuffer,
|
||||
aLength * sizeof(PRUnichar));
|
||||
if (!m2b) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// Use 1 byte storage because we can
|
||||
char* buff = (char *)mAllocator->Alloc(aLength * sizeof(char));
|
||||
char* buff = (char *)nsMemory::Alloc(aLength * sizeof(char));
|
||||
if (!buff) {
|
||||
return;
|
||||
}
|
||||
|
@ -323,20 +301,15 @@ nsTextFragment::Append(const PRUnichar* aBuffer, PRUint32 aLength)
|
|||
|
||||
if (mState.mIs2b) {
|
||||
// Already a 2-byte string so the result will be too
|
||||
PRUnichar* buff =
|
||||
(PRUnichar*)mAllocator->Alloc((mState.mLength + aLength) *
|
||||
sizeof(PRUnichar));
|
||||
PRUnichar* buff = (PRUnichar*)nsMemory::Realloc(m2b, (mState.mLength + aLength) * sizeof(PRUnichar));
|
||||
if (!buff) {
|
||||
return;
|
||||
}
|
||||
memcpy(buff, m2b, mState.mLength * sizeof(PRUnichar));
|
||||
|
||||
memcpy(buff + mState.mLength, aBuffer, aLength * sizeof(PRUnichar));
|
||||
if (mState.mInHeap) {
|
||||
mAllocator->Free(mState.mLength * sizeof(PRUnichar), m2b);
|
||||
}
|
||||
mState.mLength += aLength;
|
||||
m2b = buff;
|
||||
mState.mInHeap = PR_TRUE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -356,8 +329,8 @@ nsTextFragment::Append(const PRUnichar* aBuffer, PRUint32 aLength)
|
|||
if (need2) {
|
||||
// The old data was 1-byte, but the new is not so we have to expand it
|
||||
// all to 2-byte
|
||||
PRUnichar* buff = (PRUnichar*)mAllocator->Alloc((mState.mLength + aLength) *
|
||||
sizeof(PRUnichar));
|
||||
PRUnichar* buff = (PRUnichar*)nsMemory::Alloc((mState.mLength + aLength) *
|
||||
sizeof(PRUnichar));
|
||||
if (!buff) {
|
||||
return;
|
||||
}
|
||||
|
@ -369,34 +342,42 @@ nsTextFragment::Append(const PRUnichar* aBuffer, PRUint32 aLength)
|
|||
|
||||
memcpy(buff + mState.mLength, aBuffer, aLength * sizeof(PRUnichar));
|
||||
|
||||
if (mState.mInHeap) {
|
||||
mAllocator->Free(mState.mLength * sizeof(char), m2b);
|
||||
}
|
||||
mState.mLength += aLength;
|
||||
mState.mIs2b = PR_TRUE;
|
||||
|
||||
if (mState.mInHeap) {
|
||||
nsMemory::Free(m2b);
|
||||
}
|
||||
m2b = buff;
|
||||
|
||||
mState.mInHeap = PR_TRUE;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// The new and the old data is all 1-byte
|
||||
char* buff =
|
||||
(char*)mAllocator->Alloc((mState.mLength + aLength) * sizeof(char));
|
||||
if (!buff) {
|
||||
return;
|
||||
char* buff;
|
||||
if (mState.mInHeap) {
|
||||
buff = (char*)nsMemory::Realloc(const_cast<char*>(m1b),
|
||||
(mState.mLength + aLength) * sizeof(char));
|
||||
if (!buff) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
buff = (char*)nsMemory::Alloc((mState.mLength + aLength) * sizeof(char));
|
||||
if (!buff) {
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(buff, m1b, mState.mLength);
|
||||
|
||||
memcpy(buff, m1b, mState.mLength);
|
||||
mState.mInHeap = PR_TRUE;
|
||||
}
|
||||
|
||||
for (PRUint32 i = 0; i < aLength; ++i) {
|
||||
buff[mState.mLength + i] = (char)aBuffer[i];
|
||||
}
|
||||
|
||||
if (mState.mInHeap) {
|
||||
mAllocator->Free(mState.mLength * sizeof(char), const_cast<char*>(m1b));
|
||||
}
|
||||
mState.mInHeap = PR_TRUE;
|
||||
m1b = buff;
|
||||
mState.mLength += aLength;
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
#include "nsAString.h"
|
||||
class nsString;
|
||||
class nsCString;
|
||||
class nsDOMNodeAllocator;
|
||||
|
||||
// XXX should this normalize the code to keep a \u0000 at the end?
|
||||
|
||||
|
@ -86,12 +85,14 @@ public:
|
|||
/**
|
||||
* Default constructor. Initialize the fragment to be empty.
|
||||
*/
|
||||
nsTextFragment(nsDOMNodeAllocator* aAllocator);
|
||||
nsTextFragment()
|
||||
: m1b(nsnull), mAllBits(0)
|
||||
{
|
||||
NS_ASSERTION(sizeof(FragmentBits) == 4, "Bad field packing!");
|
||||
}
|
||||
|
||||
~nsTextFragment();
|
||||
|
||||
nsDOMNodeAllocator* Allocator() { return mAllocator; }
|
||||
|
||||
/**
|
||||
* Change the contents of this fragment to be a copy of the
|
||||
* the argument fragment.
|
||||
|
@ -204,7 +205,6 @@ public:
|
|||
|
||||
private:
|
||||
void ReleaseText();
|
||||
void* CloneMemory(const void* aPtr, PRSize aSize);
|
||||
|
||||
union {
|
||||
PRUnichar *m2b;
|
||||
|
@ -215,7 +215,6 @@ private:
|
|||
PRUint32 mAllBits;
|
||||
FragmentBits mState;
|
||||
};
|
||||
nsDOMNodeAllocator* mAllocator;
|
||||
};
|
||||
|
||||
#endif /* nsTextFragment_h___ */
|
||||
|
|
|
@ -114,9 +114,9 @@ public:
|
|||
virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,
|
||||
PRBool aCloneText) const
|
||||
{
|
||||
nsAttributeTextNode *it = new (aNodeInfo) nsAttributeTextNode(aNodeInfo,
|
||||
mNameSpaceID,
|
||||
mAttrName);
|
||||
nsAttributeTextNode *it = new nsAttributeTextNode(aNodeInfo,
|
||||
mNameSpaceID,
|
||||
mAttrName);
|
||||
if (it && aCloneText) {
|
||||
it->mText = mText;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ NS_NewTextNode(nsIContent** aInstancePtrResult,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsIContent *instance = new (ni) nsTextNode(ni);
|
||||
nsIContent *instance = new nsTextNode(ni);
|
||||
if (!instance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ nsTextNode::IsNodeOfType(PRUint32 aFlags) const
|
|||
nsGenericDOMDataNode*
|
||||
nsTextNode::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
|
||||
{
|
||||
nsTextNode *it = new (aNodeInfo) nsTextNode(aNodeInfo);
|
||||
nsTextNode *it = new nsTextNode(aNodeInfo);
|
||||
if (it && aCloneText) {
|
||||
it->mText = mText;
|
||||
}
|
||||
|
@ -280,8 +280,8 @@ NS_NewAttributeContent(nsNodeInfoManager *aNodeInfoManager,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsAttributeTextNode* textNode = new (ni) nsAttributeTextNode(ni, aNameSpaceID,
|
||||
aAttrName);
|
||||
nsAttributeTextNode* textNode = new nsAttributeTextNode(ni, aNameSpaceID,
|
||||
aAttrName);
|
||||
if (!textNode) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ NS_IMPL_ELEMENT_CLONE(nsXMLEventsElement)
|
|||
nsresult
|
||||
NS_NewXMLEventsElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
nsXMLEventsElement* it = new (aNodeInfo) nsXMLEventsElement(aNodeInfo);
|
||||
nsXMLEventsElement* it = new nsXMLEventsElement(aNodeInfo);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -232,6 +232,7 @@ public:
|
|||
nsresult GetHrefURIForAnchors(nsIURI** aURI) const;
|
||||
|
||||
// HTML element methods
|
||||
void Compact() { mAttrsAndChildren.Compact(); }
|
||||
const nsAttrValue* GetParsedAttr(nsIAtom* aAttr) const
|
||||
{
|
||||
return mAttrsAndChildren.GetAttr(aAttr);
|
||||
|
@ -972,15 +973,14 @@ private:
|
|||
nsGenericHTMLElement* \
|
||||
NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
|
||||
{ \
|
||||
return new (aNodeInfo) nsHTML##_elementName##Element(aNodeInfo); \
|
||||
return new nsHTML##_elementName##Element(aNodeInfo); \
|
||||
}
|
||||
|
||||
#define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName) \
|
||||
nsGenericHTMLElement* \
|
||||
NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
|
||||
{ \
|
||||
return \
|
||||
new (aNodeInfo) nsHTML##_elementName##Element(aNodeInfo, aFromParser); \
|
||||
return new nsHTML##_elementName##Element(aNodeInfo, aFromParser); \
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ public:
|
|||
nsGenericHTMLElement*
|
||||
NS_NewHTMLCanvasElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
|
||||
{
|
||||
return new (aNodeInfo) nsHTMLCanvasElement(aNodeInfo);
|
||||
return new nsHTMLCanvasElement(aNodeInfo);
|
||||
}
|
||||
|
||||
nsHTMLCanvasElement::nsHTMLCanvasElement(nsINodeInfo *aNodeInfo)
|
||||
|
|
|
@ -461,7 +461,7 @@ ShouldBeInElements(nsIFormControl* aFormControl)
|
|||
nsGenericHTMLElement*
|
||||
NS_NewHTMLFormElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
|
||||
{
|
||||
nsHTMLFormElement* it = new (aNodeInfo) nsHTMLFormElement(aNodeInfo);
|
||||
nsHTMLFormElement* it = new nsHTMLFormElement(aNodeInfo);
|
||||
if (!it) {
|
||||
return nsnull;
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ NS_NewHTMLImageElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
|
|||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
}
|
||||
|
||||
return new (nodeInfo) nsHTMLImageElement(nodeInfo);
|
||||
return new nsHTMLImageElement(nodeInfo);
|
||||
}
|
||||
|
||||
nsHTMLImageElement::nsHTMLImageElement(nsINodeInfo *aNodeInfo)
|
||||
|
|
|
@ -430,8 +430,7 @@ nsHTMLInputElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
nsHTMLInputElement *it =
|
||||
new (aNodeInfo) nsHTMLInputElement(aNodeInfo, PR_FALSE);
|
||||
nsHTMLInputElement *it = new nsHTMLInputElement(aNodeInfo, PR_FALSE);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ NS_NewHTMLOptionElement(nsINodeInfo *aNodeInfo, PRBool aFromParser)
|
|||
NS_ENSURE_SUCCESS(rv, nsnull);
|
||||
}
|
||||
|
||||
return new (nodeInfo) nsHTMLOptionElement(nodeInfo);
|
||||
return new nsHTMLOptionElement(nodeInfo);
|
||||
}
|
||||
|
||||
nsHTMLOptionElement::nsHTMLOptionElement(nsINodeInfo *aNodeInfo)
|
||||
|
|
|
@ -420,8 +420,7 @@ nsHTMLScriptElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
nsHTMLScriptElement* it =
|
||||
new (aNodeInfo) nsHTMLScriptElement(aNodeInfo, PR_FALSE);
|
||||
nsHTMLScriptElement* it = new nsHTMLScriptElement(aNodeInfo, PR_FALSE);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -931,6 +931,7 @@ SinkContext::CloseContainer(const nsHTMLTag aTag, PRBool aMalformed)
|
|||
|
||||
nsGenericHTMLElement* content = mStack[mStackPos].mContent;
|
||||
|
||||
content->Compact();
|
||||
|
||||
// If we're in a state where we do append notifications as
|
||||
// we go up the tree, and we're at the level where the next
|
||||
|
|
|
@ -47,7 +47,7 @@ NS_NewMathMLElement(nsIContent** aResult, nsINodeInfo* aNodeInfo)
|
|||
{
|
||||
aNodeInfo->SetIDAttributeAtom(nsGkAtoms::id);
|
||||
|
||||
nsMathMLElement* it = new (aNodeInfo) nsMathMLElement(aNodeInfo);
|
||||
nsMathMLElement* it = new nsMathMLElement(aNodeInfo);
|
||||
NS_ENSURE_TRUE(it, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*aResult = it);
|
||||
|
|
|
@ -97,9 +97,7 @@ nsSVGEnumMapping nsSVGElement::sSVGUnitTypesMap[] = {
|
|||
};
|
||||
|
||||
nsSVGElement::nsSVGElement(nsINodeInfo *aNodeInfo)
|
||||
: nsSVGElementBase(aNodeInfo),
|
||||
mMappedAttributes(aNodeInfo->NodeInfoManager()->NodeAllocator()),
|
||||
mSuppressNotification(PR_FALSE)
|
||||
: nsSVGElementBase(aNodeInfo), mSuppressNotification(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -322,7 +322,7 @@ NS_NewSVG##_elementName##Element(nsIContent **aResult, \
|
|||
nsINodeInfo *aNodeInfo) \
|
||||
{ \
|
||||
nsSVG##_elementName##Element *it = \
|
||||
new (aNodeInfo) nsSVG##_elementName##Element(aNodeInfo); \
|
||||
new nsSVG##_elementName##Element(aNodeInfo); \
|
||||
if (!it) \
|
||||
return NS_ERROR_OUT_OF_MEMORY; \
|
||||
\
|
||||
|
|
|
@ -133,7 +133,7 @@ nsSVGUseElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|||
{
|
||||
*aResult = nsnull;
|
||||
|
||||
nsSVGUseElement *it = new (aNodeInfo) nsSVGUseElement(aNodeInfo);
|
||||
nsSVGUseElement *it = new nsSVGUseElement(aNodeInfo);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ NS_NewXMLCDATASection(nsIContent** aInstancePtrResult,
|
|||
getter_AddRefs(ni));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXMLCDATASection *instance = new (ni) nsXMLCDATASection(ni);
|
||||
nsXMLCDATASection *instance = new nsXMLCDATASection(ni);
|
||||
if (!instance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ nsXMLCDATASection::GetNodeType(PRUint16* aNodeType)
|
|||
nsGenericDOMDataNode*
|
||||
nsXMLCDATASection::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
|
||||
{
|
||||
nsXMLCDATASection *it = new (aNodeInfo) nsXMLCDATASection(aNodeInfo);
|
||||
nsXMLCDATASection *it = new nsXMLCDATASection(aNodeInfo);
|
||||
if (it && aCloneText) {
|
||||
it->mText = mText;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
nsresult
|
||||
NS_NewXMLElement(nsIContent** aInstancePtrResult, nsINodeInfo *aNodeInfo)
|
||||
{
|
||||
nsXMLElement* it = new (aNodeInfo) nsXMLElement(aNodeInfo);
|
||||
nsXMLElement* it = new nsXMLElement(aNodeInfo);
|
||||
if (!it) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXMLProcessingInstruction *instance =
|
||||
new (ni) nsXMLProcessingInstruction(ni, aTarget, aData);
|
||||
new nsXMLProcessingInstruction(ni, aTarget, aData);
|
||||
if (!instance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -176,7 +176,7 @@ nsXMLProcessingInstruction::CloneDataNode(nsINodeInfo *aNodeInfo,
|
|||
nsAutoString data;
|
||||
nsGenericDOMDataNode::GetData(data);
|
||||
|
||||
return new (aNodeInfo) nsXMLProcessingInstruction(aNodeInfo, mTarget, data);
|
||||
return new nsXMLProcessingInstruction(aNodeInfo, mTarget, data);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
|
|
@ -246,7 +246,7 @@ nsXMLStylesheetPI::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) cons
|
|||
nsAutoString data;
|
||||
nsGenericDOMDataNode::GetData(data);
|
||||
|
||||
return new (aNodeInfo) nsXMLStylesheetPI(aNodeInfo, data);
|
||||
return new nsXMLStylesheetPI(aNodeInfo, data);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -265,7 +265,7 @@ NS_NewXMLStylesheetProcessingInstruction(nsIContent** aInstancePtrResult,
|
|||
getter_AddRefs(ni));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsXMLStylesheetPI *instance = new (ni) nsXMLStylesheetPI(ni, aData);
|
||||
nsXMLStylesheetPI *instance = new nsXMLStylesheetPI(ni, aData);
|
||||
if (!instance) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -1003,8 +1003,7 @@ NS_NewXTFElementWrapper(nsIXTFElement* aXTFElement,
|
|||
*aResult = nsnull;
|
||||
NS_ENSURE_ARG(aXTFElement);
|
||||
|
||||
nsXTFElementWrapper* result =
|
||||
new (aNodeInfo) nsXTFElementWrapper(aNodeInfo, aXTFElement);
|
||||
nsXTFElementWrapper* result = new nsXTFElementWrapper(aNodeInfo, aXTFElement);
|
||||
if (!result) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ nsXULElement::nsXULSlots::~nsXULSlots()
|
|||
nsINode::nsSlots*
|
||||
nsXULElement::CreateSlots()
|
||||
{
|
||||
return new (GetAllocator()) nsXULSlots(mFlagsOrSlots);
|
||||
return new nsXULSlots(mFlagsOrSlots);
|
||||
}
|
||||
|
||||
/* static */
|
||||
|
@ -270,7 +270,7 @@ already_AddRefed<nsXULElement>
|
|||
nsXULElement::Create(nsXULPrototypeElement* aPrototype, nsINodeInfo *aNodeInfo,
|
||||
PRBool aIsScriptable)
|
||||
{
|
||||
nsXULElement *element = new (aNodeInfo) nsXULElement(aNodeInfo);
|
||||
nsXULElement *element = new nsXULElement(aNodeInfo);
|
||||
if (element) {
|
||||
NS_ADDREF(element);
|
||||
|
||||
|
@ -351,7 +351,7 @@ NS_NewXULElement(nsIContent** aResult, nsINodeInfo *aNodeInfo)
|
|||
*aResult = nsnull;
|
||||
|
||||
// Create an nsXULElement with the specified namespace and tag.
|
||||
nsXULElement* element = new (aNodeInfo) nsXULElement(aNodeInfo);
|
||||
nsXULElement* element = new nsXULElement(aNodeInfo);
|
||||
NS_ENSURE_TRUE(element, NS_ERROR_OUT_OF_MEMORY);
|
||||
|
||||
NS_ADDREF(*aResult = element);
|
||||
|
@ -431,7 +431,7 @@ nsXULElement::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|||
"Didn't get the default language from proto?");
|
||||
}
|
||||
else {
|
||||
element = new (aNodeInfo) nsXULElement(aNodeInfo);
|
||||
element = new nsXULElement(aNodeInfo);
|
||||
if (element) {
|
||||
// If created from a prototype, we will already have the script
|
||||
// language specified by the proto - otherwise copy it directly
|
||||
|
|
Загрузка…
Ссылка в новой задаче