From 13b92c95bfa45f48f94d08f3702e23b51ae353cf Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Thu, 8 Jun 2006 04:28:20 +0000 Subject: [PATCH] Cache the list of form controls, so loading a large page with lots of form controls outside forms is not O(N^2). Bug 336062, r+sr=sicking git-svn-id: svn://10.0.0.236/trunk@199489 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/public/nsContentUtils.h | 7 ------- mozilla/content/base/src/nsContentUtils.cpp | 18 +----------------- .../html/document/src/nsHTMLDocument.cpp | 15 +++++++++++++++ .../content/html/document/src/nsHTMLDocument.h | 3 +++ .../html/document/src/nsIHTMLDocument.h | 11 ++++++++--- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index d048b0d6c0f..12ef8d6cefa 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -641,13 +641,6 @@ public: PRUint32 aParamsLength, nsXPIDLString& aResult); - /** - * Returns a list containing all elements in the document that are - * of type nsIContent::eHTML_FORM_CONTROL. - */ - static already_AddRefed - GetFormControlElements(nsIDocument *aDocument); - /** * Returns true if aDocument is a chrome document */ diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index cb20e780c6b..fc152a2d066 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -1507,8 +1507,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent, aContent->GetCurrentDoc()->FlushPendingNotifications(Flush_Content); nsContentList *htmlForms = htmlDocument->GetForms(); - nsRefPtr htmlFormControls = - GetFormControlElements(aDocument); + nsContentList *htmlFormControls = htmlDocument->GetFormControls(); NS_ENSURE_TRUE(htmlForms && htmlFormControls, NS_ERROR_OUT_OF_MEMORY); @@ -2456,21 +2455,6 @@ nsContentUtils::ReportToConsole(PropertiesFile aFile, return sConsoleService->LogMessage(errorObject); } -static PRBool MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID, - nsIAtom* aAtom, const nsAString& aData) -{ - return aContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL); -} - -/* static */ already_AddRefed -nsContentUtils::GetFormControlElements(nsIDocument *aDocument) -{ - nsContentList *list = new nsContentList(aDocument, - MatchFormControls, EmptyString()); - NS_IF_ADDREF(list); - return list; -} - PRBool nsContentUtils::IsChromeDoc(nsIDocument *aDocument) { diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 6aff7e0f3cf..519e8110540 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -3542,6 +3542,21 @@ nsHTMLDocument::GetForms() return mForms; } +static PRBool MatchFormControls(nsIContent* aContent, PRInt32 aNamespaceID, + nsIAtom* aAtom, const nsAString& aData) +{ + return aContent->IsNodeOfType(nsIContent::eHTML_FORM_CONTROL); +} + +nsContentList* +nsHTMLDocument::GetFormControls() +{ + if (!mFormControls) { + mFormControls = new nsContentList(this, MatchFormControls, EmptyString()); + } + + return mFormControls; +} nsresult nsHTMLDocument::CreateAndAddWyciwygChannel(void) diff --git a/mozilla/content/html/document/src/nsHTMLDocument.h b/mozilla/content/html/document/src/nsHTMLDocument.h index 213f9b28b20..81d991bd45a 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.h +++ b/mozilla/content/html/document/src/nsHTMLDocument.h @@ -120,6 +120,8 @@ public: virtual NS_HIDDEN_(nsContentList*) GetForms(); + virtual NS_HIDDEN_(nsContentList*) GetFormControls(); + virtual void ContentAppended(nsIContent* aContainer, PRInt32 aNewIndexInContainer); virtual void ContentInserted(nsIContent* aContainer, @@ -264,6 +266,7 @@ protected: nsCOMPtr mLinks; nsCOMPtr mAnchors; nsRefPtr mForms; + nsRefPtr mFormControls; /** # of forms in the document, synchronously set */ PRInt32 mNumForms; diff --git a/mozilla/content/html/document/src/nsIHTMLDocument.h b/mozilla/content/html/document/src/nsIHTMLDocument.h index 4aaf9d023a5..f657b3f8755 100644 --- a/mozilla/content/html/document/src/nsIHTMLDocument.h +++ b/mozilla/content/html/document/src/nsIHTMLDocument.h @@ -55,9 +55,8 @@ class nsIDOMHTMLBodyElement; class nsIScriptElement; #define NS_IHTMLDOCUMENT_IID \ -{ 0x4daadd67, 0x61b4, 0x4423, \ - { 0xae, 0x1a, 0x61, 0x6f, 0xed, 0x5d, 0x72, 0x3c } } - +{ 0xd28641ff, 0xd623, 0x40de, \ + { 0xb4, 0x64, 0x75, 0x02, 0xd2, 0x4f, 0x4c, 0xdd } } /** @@ -128,6 +127,12 @@ public: * Get the list of form elements in the document. */ virtual nsContentList* GetForms() = 0; + + /** + * Get the list of form controls in the document (all elements in + * the document that are of type nsIContent::eHTML_FORM_CONTROL). + */ + virtual nsContentList* GetFormControls() = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLDocument, NS_IHTMLDOCUMENT_IID)