Fixing one more part of bug 243034. Avoid wasting time on string concatenation document.write() when we don't need to concatenate. r+sr=bzbarsky@mit.edu

git-svn-id: svn://10.0.0.236/trunk@156266 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
jst%mozilla.jstenback.com
2004-05-11 22:37:31 +00:00
parent 1b6322253e
commit 94aed51def

View File

@@ -2240,23 +2240,34 @@ nsHTMLDocument::WriteCommon(const nsAString& aText,
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
++mWriteLevel;
static NS_NAMED_LITERAL_STRING(new_line, "\n");
static NS_NAMED_LITERAL_STRING(empty, "");
const nsAString *term = aNewlineTerminate ? &new_line : ∅
const nsAutoString text = aText + *term;
// Save the data in cache
if (mWyciwygChannel) {
mWyciwygChannel->WriteToCacheEntry(text);
mWyciwygChannel->WriteToCacheEntry(aText);
if (aNewlineTerminate) {
mWyciwygChannel->WriteToCacheEntry(new_line);
}
}
rv = mParser->Parse(text ,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
++mWriteLevel;
// This could be done with less code, but for performance reasons it
// makes sense to have the code for two separate Parse() calls here
// since the concatenation of strings costs more than we like. And
// why pay that price when we don't need to?
if (aNewlineTerminate) {
rv = mParser->Parse(aText + new_line,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
} else {
rv = mParser->Parse(aText,
NS_GENERATE_PARSER_KEY(),
NS_LITERAL_CSTRING("text/html"), PR_FALSE,
(!mIsWriting || (mWriteLevel > 1)));
}
--mWriteLevel;