Putting XUL prototype elements on a diet. Bug 26429.

r=ben, sr=brendan
This commit is contained in:
varga%netscape.com 2002-09-25 09:56:09 +00:00
parent d584b75924
commit a068886905
7 changed files with 42 additions and 50 deletions

View File

@ -727,7 +727,7 @@ nsXBLContentSink::CreateElement(const PRUnichar** aAtts,
nsIContent** aResult)
{
if (aNameSpaceID == nsXULAtoms::nameSpaceID) {
nsXULPrototypeElement* prototype = new nsXULPrototypeElement(0);
nsXULPrototypeElement* prototype = new nsXULPrototypeElement();
if (!prototype)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -440,7 +440,7 @@ PRInt32 nsXULElement::kNameSpaceID_RDF;
PRInt32 nsXULElement::kNameSpaceID_XUL;
#ifdef XUL_PROTOTYPE_ATTRIBUTE_METERING
PRUint32 nsXULPrototypeAttribute::gNumElements;
PRUint32 nsXULProtlotypeAttribute::gNumElements;
PRUint32 nsXULPrototypeAttribute::gNumAttributes;
PRUint32 nsXULPrototypeAttribute::gNumEventHandlers;
PRUint32 nsXULPrototypeAttribute::gNumCacheTests;
@ -4933,7 +4933,6 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
// Write basic prototype data
rv = aStream->Write32(mType);
rv |= aStream->Write32(mLineNo);
// Write Node Info
PRInt32 index = aNodeInfos->IndexOf(mNodeInfo);
@ -4968,7 +4967,7 @@ nsXULPrototypeElement::Serialize(nsIObjectOutputStream* aStream,
nsXULPrototypeScript* script = NS_STATIC_CAST(nsXULPrototypeScript*, child);
if (script) {
rv |= aStream->WriteBoolean(script->mOutOfLine);
rv |= aStream->Write8(script->mOutOfLine);
if (! script->mOutOfLine)
rv |= script->Serialize(aStream, aContext, aNodeInfos);
else
@ -4992,11 +4991,8 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
NS_PRECONDITION(aNodeInfos, "missing nodeinfo array");
nsresult rv;
PRUint32 number;
rv = aStream->Read32(&number);
mLineNo = (PRInt32)number;
// Read Node Info
PRUint32 number;
rv |= aStream->Read32(&number);
mNodeInfo = do_QueryElementAt(aNodeInfos, number);
if (!mNodeInfo)
@ -5043,13 +5039,13 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
rv |= aStream->Read32(&number);
mNumChildren = PRInt32(number);
if (mNumChildren > 0) {
mChildren = new nsXULPrototypeNode*[mNumChildren];
memset(mChildren, 0, sizeof(nsXULPrototypeNode*) * mNumChildren);
if (! mChildren)
return NS_ERROR_OUT_OF_MEMORY;
memset(mChildren, 0, sizeof(nsXULPrototypeNode*) * mNumChildren);
for (i = 0; i < mNumChildren; i++) {
rv |= aStream->Read32(&number);
@ -5059,7 +5055,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
switch (childType) {
case eType_Element:
child = new nsXULPrototypeElement(-1);
child = new nsXULPrototypeElement();
if (! child)
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
@ -5068,7 +5064,7 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
aNodeInfos);
break;
case eType_Text:
child = new nsXULPrototypeText(-1);
child = new nsXULPrototypeText();
if (! child)
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
@ -5078,14 +5074,14 @@ nsXULPrototypeElement::Deserialize(nsIObjectInputStream* aStream,
break;
case eType_Script:
// language version obtained during deserialization.
child = new nsXULPrototypeScript(-1, nsnull);
child = new nsXULPrototypeScript(0, nsnull);
if (! child)
return NS_ERROR_OUT_OF_MEMORY;
child->mType = childType;
nsXULPrototypeScript* script = NS_STATIC_CAST(nsXULPrototypeScript*, child);
if (script) {
rv |= aStream->ReadBoolean(&script->mOutOfLine);
rv |= aStream->Read8(&script->mOutOfLine);
if (! script->mOutOfLine) {
rv |= script->Deserialize(aStream, aContext,
aDocumentURI, aNodeInfos);
@ -5137,8 +5133,9 @@ nsXULPrototypeElement::GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, nsAString&
// nsXULPrototypeScript
//
nsXULPrototypeScript::nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script, aLineNo),
nsXULPrototypeScript::nsXULPrototypeScript(PRUint16 aLineNo, const char *aVersion)
: nsXULPrototypeNode(eType_Script),
mLineNo(aLineNo),
mSrcLoading(PR_FALSE),
mOutOfLine(PR_TRUE),
mSrcLoadWaiters(nsnull),
@ -5165,7 +5162,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream,
nsresult rv;
// Write basic prototype data
aStream->Write32(mLineNo);
aStream->Write16(mLineNo);
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nsnull || !mJSObject,
"script source still loading when serializing?!");
@ -5228,9 +5225,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream,
nsresult rv;
// Read basic prototype data
PRUint32 number;
aStream->Read32(&number);
mLineNo = (PRInt32)number;
aStream->Read16(&mLineNo);
NS_ASSERTION(!mSrcLoading || mSrcLoadWaiters != nsnull || !mJSObject,
"prototype script not well-initialized when deserializing?!");
@ -5410,7 +5405,7 @@ nsresult
nsXULPrototypeScript::Compile(const PRUnichar* aText,
PRInt32 aTextLength,
nsIURI* aURI,
PRInt32 aLineNo,
PRUint16 aLineNo,
nsIDocument* aDocument,
nsIXULPrototypeDocument* aPrototypeDocument)
{
@ -5470,7 +5465,7 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText,
scopeObject,
principal,
urlspec.get(),
PRUint32(aLineNo),
aLineNo,
mLangVersion,
(void**)&mJSObject);
@ -5520,7 +5515,6 @@ nsXULPrototypeText::Serialize(nsIObjectOutputStream* aStream,
// Write basic prototype data
rv = aStream->Write32(mType);
rv |= aStream->Write32(mLineNo);
rv |= aStream->WriteWStringZ(mValue.get());
@ -5536,10 +5530,6 @@ nsXULPrototypeText::Deserialize(nsIObjectInputStream* aStream,
nsresult rv;
// Write basic prototype data
PRUint32 number;
rv = aStream->Read32(&number);
mLineNo = (PRInt32)number;
PRUnichar* str = nsnull;
rv |= aStream->ReadWStringZ(&str);
mValue.Adopt(str);

View File

@ -196,7 +196,6 @@ public:
Type mType;
PRInt32 mLineNo;
PRInt32 mRefCnt;
virtual ~nsXULPrototypeNode() {}
@ -218,15 +217,15 @@ public:
virtual void ReleaseSubtree() { Release(); };
protected:
nsXULPrototypeNode(Type aType, PRInt32 aLineNo)
: mType(aType), mLineNo(aLineNo), mRefCnt(1) {}
nsXULPrototypeNode(Type aType)
: mType(aType), mRefCnt(1) {}
};
class nsXULPrototypeElement : public nsXULPrototypeNode
{
public:
nsXULPrototypeElement(PRInt32 aLineNo)
: nsXULPrototypeNode(eType_Element, aLineNo),
nsXULPrototypeElement()
: nsXULPrototypeNode(eType_Element),
mNumChildren(0),
mChildren(nsnull),
mNumAttributes(0),
@ -302,7 +301,7 @@ class nsXULDocument;
class nsXULPrototypeScript : public nsXULPrototypeNode
{
public:
nsXULPrototypeScript(PRInt32 aLineNo, const char *aVersion);
nsXULPrototypeScript(PRUint16 aLineNo, const char *aVersion);
virtual ~nsXULPrototypeScript();
virtual nsresult Serialize(nsIObjectOutputStream* aStream,
@ -316,13 +315,14 @@ public:
nsIScriptContext* aContext);
nsresult Compile(const PRUnichar* aText, PRInt32 aTextLength,
nsIURI* aURI, PRInt32 aLineNo,
nsIURI* aURI, PRUint16 aLineNo,
nsIDocument* aDocument,
nsIXULPrototypeDocument* aPrototypeDocument);
nsCOMPtr<nsIURI> mSrcURI;
PRBool mSrcLoading;
PRBool mOutOfLine;
PRUint16 mLineNo;
PRPackedBool mSrcLoading;
PRPackedBool mOutOfLine;
nsXULDocument* mSrcLoadWaiters; // [OWNER] but not COMPtr
JSObject* mJSObject;
const char* mLangVersion;
@ -346,8 +346,8 @@ protected:
class nsXULPrototypeText : public nsXULPrototypeNode
{
public:
nsXULPrototypeText(PRInt32 aLineNo)
: nsXULPrototypeNode(eType_Text, aLineNo)
nsXULPrototypeText()
: nsXULPrototypeNode(eType_Text)
{
MOZ_COUNT_CTOR(nsXULPrototypeText);
}

View File

@ -133,7 +133,7 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult);
const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL";
// increase the subtractor when changing version
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 5)
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 6)
#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024)
#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024)

View File

@ -734,7 +734,7 @@ XULContentSinkImpl::FlushText(PRBool aCreateTextNode)
break;
// Trim the leading and trailing whitespace
nsXULPrototypeText* text = new nsXULPrototypeText(/* line number */ -1);
nsXULPrototypeText* text = new nsXULPrototypeText();
if (! text)
return NS_ERROR_OUT_OF_MEMORY;
@ -803,7 +803,7 @@ nsresult
XULContentSinkImpl::CreateElement(nsINodeInfo *aNodeInfo,
nsXULPrototypeElement** aResult)
{
nsXULPrototypeElement* element = new nsXULPrototypeElement(/* line number */ -1);
nsXULPrototypeElement* element = new nsXULPrototypeElement();
if (! element)
return NS_ERROR_OUT_OF_MEMORY;

View File

@ -6059,7 +6059,13 @@ nsXULDocument::CreateElement(nsXULPrototypeElement* aPrototype, nsIContent** aRe
nsCOMPtr<nsIContent> result;
if (aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
if (aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
// If it's a XUL element, it'll be lightweight until somebody
// monkeys with it.
rv = nsXULElement::Create(aPrototype, this, PR_TRUE, getter_AddRefs(result));
if (NS_FAILED(rv)) return rv;
}
else if (aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XHTML)) {
// If it's an HTML element, it's gonna be heavyweight no matter
// what. So we need to copy everything out of the prototype
// into the element.
@ -6077,7 +6083,7 @@ nsXULDocument::CreateElement(nsXULPrototypeElement* aPrototype, nsIContent** aRe
rv = AddAttributes(aPrototype, result);
if (NS_FAILED(rv)) return rv;
}
else if (!aPrototype->mNodeInfo->NamespaceEquals(kNameSpaceID_XUL)) {
else {
// If it's not a XUL element, it's gonna be heavyweight no matter
// what. So we need to copy everything out of the prototype
// into the element.
@ -6101,12 +6107,6 @@ nsXULDocument::CreateElement(nsXULPrototypeElement* aPrototype, nsIContent** aRe
rv = AddAttributes(aPrototype, result);
if (NS_FAILED(rv)) return rv;
}
else {
// If it's a XUL element, it'll be lightweight until somebody
// monkeys with it.
rv = nsXULElement::Create(aPrototype, this, PR_TRUE, getter_AddRefs(result));
if (NS_FAILED(rv)) return rv;
}
result->SetContentID(mNextContentID++);
@ -6376,11 +6376,13 @@ nsXULDocument::OverlayForwardReference::Resolve()
rv = mDocument->AddSubtreeToDocument(target);
if (NS_FAILED(rv)) return eResolve_Error;
#ifdef PR_LOGGING
nsCAutoString idC;
idC.AssignWithConversion(id);
PR_LOG(gXULLog, PR_LOG_ALWAYS,
("xul: overlay resolved '%s'",
idC.get()));
#endif
mResolved = PR_TRUE;
return eResolve_Succeeded;

View File

@ -358,7 +358,7 @@ nsXULPrototypeDocument::Read(nsIObjectInputStream* aStream)
return NS_ERROR_OUT_OF_MEMORY;
rv |= mGlobalObject->SetGlobalObjectOwner(this); // does not refcount
mRoot = new nsXULPrototypeElement(-1);
mRoot = new nsXULPrototypeElement();
if (! mRoot)
return NS_ERROR_OUT_OF_MEMORY;