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
This commit is contained in:
bzbarsky%mit.edu 2006-06-08 04:28:20 +00:00
parent 55e0fdaec2
commit 6e37157407
5 changed files with 27 additions and 27 deletions

View File

@ -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<nsContentList>
GetFormControlElements(nsIDocument *aDocument);
/**
* Returns true if aDocument is a chrome document
*/

View File

@ -1507,8 +1507,7 @@ nsContentUtils::GenerateStateKey(nsIContent* aContent,
aContent->GetCurrentDoc()->FlushPendingNotifications(Flush_Content);
nsContentList *htmlForms = htmlDocument->GetForms();
nsRefPtr<nsContentList> 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<nsContentList>
nsContentUtils::GetFormControlElements(nsIDocument *aDocument)
{
nsContentList *list = new nsContentList(aDocument,
MatchFormControls, EmptyString());
NS_IF_ADDREF(list);
return list;
}
PRBool
nsContentUtils::IsChromeDoc(nsIDocument *aDocument)
{

View File

@ -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)

View File

@ -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<nsIDOMHTMLCollection> mLinks;
nsCOMPtr<nsIDOMHTMLCollection> mAnchors;
nsRefPtr<nsContentList> mForms;
nsRefPtr<nsContentList> mFormControls;
/** # of forms in the document, synchronously set */
PRInt32 mNumForms;

View File

@ -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)