Reduce bloat by eliminating nsString member variable (size of nsString and double-on-fault growth). r=jag sr=hyatt b=109963

This commit is contained in:
dbaron%fas.harvard.edu 2001-11-16 02:17:04 +00:00
Родитель 4a2ad7bbf6
Коммит 5e289d22b7
2 изменённых файлов: 22 добавлений и 5 удалений

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

@ -50,7 +50,9 @@
MOZ_DECL_CTOR_COUNTER(nsXBLProtoImplField); MOZ_DECL_CTOR_COUNTER(nsXBLProtoImplField);
nsXBLProtoImplField::nsXBLProtoImplField(const nsAReadableString* aName, const nsAReadableString* aReadOnly) nsXBLProtoImplField::nsXBLProtoImplField(const nsAReadableString* aName, const nsAReadableString* aReadOnly)
:nsXBLProtoImplMember(aName) : nsXBLProtoImplMember(aName),
mFieldText(nsnull),
mFieldTextLength(0)
{ {
MOZ_COUNT_CTOR(nsXBLProtoImplField); MOZ_COUNT_CTOR(nsXBLProtoImplField);
mJSAttributes = JSPROP_ENUMERATE; mJSAttributes = JSPROP_ENUMERATE;
@ -64,6 +66,8 @@ nsXBLProtoImplField::nsXBLProtoImplField(const nsAReadableString* aName, const n
nsXBLProtoImplField::~nsXBLProtoImplField() nsXBLProtoImplField::~nsXBLProtoImplField()
{ {
MOZ_COUNT_DTOR(nsXBLProtoImplField); MOZ_COUNT_DTOR(nsXBLProtoImplField);
if (mFieldText)
nsMemory::Free(mFieldText);
} }
void void
@ -74,14 +78,25 @@ nsXBLProtoImplField::Destroy(PRBool aIsCompiled)
void void
nsXBLProtoImplField::AppendFieldText(const nsAReadableString& aText) nsXBLProtoImplField::AppendFieldText(const nsAReadableString& aText)
{ {
mFieldText += aText; if (mFieldText) {
nsDependentString fieldTextStr(mFieldText, mFieldTextLength);
const nsAString& newFieldText = fieldTextStr + aText;
PRUnichar* temp = mFieldText;
mFieldText = ToNewUnicode(newFieldText);
mFieldTextLength = newFieldText.Length();
nsMemory::Free(temp);
}
else {
mFieldText = ToNewUnicode(aText);
mFieldTextLength = aText.Length();
}
} }
nsresult nsresult
nsXBLProtoImplField::InstallMember(nsIScriptContext* aContext, nsIContent* aBoundElement, nsXBLProtoImplField::InstallMember(nsIScriptContext* aContext, nsIContent* aBoundElement,
void* aScriptObject, void* aTargetClassObject) void* aScriptObject, void* aTargetClassObject)
{ {
if (mFieldText.IsEmpty()) if (mFieldTextLength == 0)
return NS_OK; // nothing to do. return NS_OK; // nothing to do.
JSContext* cx = (JSContext*) aContext->GetNativeContext(); JSContext* cx = (JSContext*) aContext->GetNativeContext();
@ -93,7 +108,8 @@ nsXBLProtoImplField::InstallMember(nsIScriptContext* aContext, nsIContent* aBoun
// compile the literal string // compile the literal string
jsval result = nsnull; jsval result = nsnull;
PRBool undefined; PRBool undefined;
aContext->EvaluateStringWithValue(mFieldText, aContext->EvaluateStringWithValue(nsDependentString(mFieldText,
mFieldTextLength),
scriptObject, scriptObject,
nsnull, nsnull, 0, nsnull, nsnull, nsnull, 0, nsnull,
(void*) &result, &undefined); (void*) &result, &undefined);

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

@ -61,7 +61,8 @@ public:
virtual nsresult CompileMember(nsIScriptContext* aContext, const nsCString& aClassStr, void* aClassObject); virtual nsresult CompileMember(nsIScriptContext* aContext, const nsCString& aClassStr, void* aClassObject);
protected: protected:
nsString mFieldText; PRUnichar* mFieldText;
PRUint32 mFieldTextLength;
uintN mJSAttributes; uintN mJSAttributes;
}; };