From d55a9c4d4f3309d3ee30762d04212eea5e82b7e5 Mon Sep 17 00:00:00 2001 From: Olli Pettay Date: Sat, 24 Apr 2010 13:41:02 +0300 Subject: [PATCH] Bug 561173 - Reduce QIing and Addref/Release while setting innerHTML, r=jst, a=1hourlimit --- content/base/public/nsContentUtils.h | 2 +- content/base/src/nsContentUtils.cpp | 19 +++++++++---------- content/base/src/nsRange.cpp | 5 ++--- .../html/content/src/nsGenericHTMLElement.cpp | 8 +++----- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 570394881e6..d6de1e8b4e6 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -1019,7 +1019,7 @@ public: * transferred to the caller. * @param aReturn [out] the created DocumentFragment */ - static nsresult CreateContextualFragment(nsIDOMNode* aContextNode, + static nsresult CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment, PRBool aWillOwnFragment, nsIDOMDocumentFragment** aReturn); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 82578a5623f..2ecd5a5252f 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -3696,27 +3696,26 @@ nsContentUtils::IsValidNodeName(nsIAtom *aLocalName, nsIAtom *aPrefix, /* static */ nsresult -nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode, +nsContentUtils::CreateContextualFragment(nsINode* aContextNode, const nsAString& aFragment, PRBool aWillOwnFragment, nsIDOMDocumentFragment** aReturn) { - NS_ENSURE_ARG(aContextNode); *aReturn = nsnull; + NS_ENSURE_ARG(aContextNode); nsresult rv; - nsCOMPtr node = do_QueryInterface(aContextNode); - NS_ENSURE_TRUE(node, NS_ERROR_NOT_AVAILABLE); // If we don't have a document here, we can't get the right security context // for compiling event handlers... so just bail out. - nsCOMPtr document = node->GetOwnerDoc(); + nsCOMPtr document = aContextNode->GetOwnerDoc(); NS_ENSURE_TRUE(document, NS_ERROR_NOT_AVAILABLE); - - PRBool bCaseSensitive = !document->IsHTML(); - nsCOMPtr htmlDoc(do_QueryInterface(document)); - PRBool isHTML = htmlDoc && !bCaseSensitive; + PRBool isHTML = document->IsHTML(); +#ifdef DEBUG + nsCOMPtr htmlDoc = do_QueryInterface(document); + NS_ASSERTION(!isHTML || htmlDoc, "Should have HTMLDocument here!"); +#endif if (isHTML && nsHtml5Module::sEnabled) { // See if the document has a cached fragment parser. nsHTMLDocument is the @@ -3760,7 +3759,7 @@ nsContentUtils::CreateContextualFragment(nsIDOMNode* aContextNode, (document->GetCompatibilityMode() == eCompatibility_NavQuirks)); } - NS_ADDREF(*aReturn = frag); + frag.swap(*aReturn); document->SetFragmentParser(parser); return NS_OK; } diff --git a/content/base/src/nsRange.cpp b/content/base/src/nsRange.cpp index ba92380c787..c5b2faa07d0 100644 --- a/content/base/src/nsRange.cpp +++ b/content/base/src/nsRange.cpp @@ -2033,10 +2033,9 @@ NS_IMETHODIMP nsRange::CreateContextualFragment(const nsAString& aFragment, nsIDOMDocumentFragment** aReturn) { - nsCOMPtr start = do_QueryInterface(mStartParent); if (mIsPositioned) { - return nsContentUtils::CreateContextualFragment(start, aFragment, PR_TRUE, - aReturn); + return nsContentUtils::CreateContextualFragment(mStartParent, aFragment, + PR_TRUE, aReturn); } return NS_ERROR_FAILURE; } diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index d4d4ae3e43f..748152d181c 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -681,14 +681,12 @@ nsGenericHTMLElement::SetInnerHTML(const nsAString& aInnerHTML) loader->SetEnabled(PR_FALSE); } - nsCOMPtr thisNode(do_QueryInterface(static_cast - (this))); - nsresult rv = nsContentUtils::CreateContextualFragment(thisNode, aInnerHTML, + nsresult rv = nsContentUtils::CreateContextualFragment(this, aInnerHTML, PR_FALSE, getter_AddRefs(df)); + nsCOMPtr fragment = do_QueryInterface(df); if (NS_SUCCEEDED(rv)) { - nsCOMPtr tmpNode; - rv = thisNode->AppendChild(df, getter_AddRefs(tmpNode)); + static_cast(this)->AppendChild(fragment, &rv); } if (scripts_enabled) {