From 94aed51defbfb843a0b58397ab301a9c5d15f8d8 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Tue, 11 May 2004 22:37:31 +0000 Subject: [PATCH] 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 --- .../html/document/src/nsHTMLDocument.cpp | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index c80b8d93f65..9d81d8e45c5 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -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;