Bug 564569. Speed up the cache-hit case of getElementsBy(Class)Name. r=jst

This commit is contained in:
Boris Zbarsky
2010-06-08 15:58:26 -04:00
parent 15674c009e
commit d495ce78a5
5 changed files with 66 additions and 48 deletions

View File

@@ -2291,6 +2291,13 @@ nsHTMLDocument::MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
*elementName, eCaseMatters);
}
/* static */
void*
nsHTMLDocument::UseExistingNameString(nsINode* aRootNode, const nsString* aName)
{
return const_cast<nsString*>(aName);
}
NS_IMETHODIMP
nsHTMLDocument::GetElementsByName(const nsAString& aElementName,
nsIDOMNodeList** aReturn)

View File

@@ -163,13 +163,8 @@ public:
nsIContent *GetBody(nsresult *aResult);
already_AddRefed<nsContentList> GetElementsByName(const nsAString & aName)
{
nsString* elementNameData = new nsString(aName);
return NS_GetFuncStringContentList(this,
MatchNameAttribute,
nsContentUtils::DestroyMatchString,
elementNameData,
*elementNameData);
return NS_GetFuncStringContentList(this, MatchNameAttribute, nsnull,
UseExistingNameString, aName);
}
// nsIDOMNSHTMLDocument interface
@@ -259,6 +254,7 @@ protected:
nsIAtom* aAtom, void* aData);
static PRBool MatchNameAttribute(nsIContent* aContent, PRInt32 aNamespaceID,
nsIAtom* aAtom, void* aData);
static void* UseExistingNameString(nsINode* aRootNode, const nsString* aName);
static void DocumentWriteTerminationFunc(nsISupports *aRef);