New NameEquals method on nsIDocShellTreeItem to reduce unnecessary strdup'ing as FindChildWithName walks through its children looking for a matching item. b=102576 r=radha@netscape.com sr=rpotts@netscape.com

This commit is contained in:
locka@iol.ie
2001-10-20 11:42:35 +00:00
parent 881e1a7567
commit fbbef8546f
3 changed files with 37 additions and 3 deletions

View File

@@ -1428,6 +1428,15 @@ nsDocShell::SetName(const PRUnichar * aName)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::NameEquals(const PRUnichar *aName, PRBool *_retval)
{
NS_ENSURE_ARG_POINTER(aName);
NS_ENSURE_ARG_POINTER(_retval);
*_retval = mName.Equals(aName);
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetItemType(PRInt32 * aItemType)
{
@@ -1908,7 +1917,6 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
*_retval = nsnull; // if we don't find one, we return NS_OK and a null result
nsDependentString name(aName);
nsXPIDLString childName;
PRInt32 i, n = mChildren.Count();
for (i = 0; i < n; i++) {
@@ -1920,8 +1928,9 @@ nsDocShell::FindChildWithName(const PRUnichar * aName,
if (aSameType && (childType != mItemType))
continue;
child->GetName(getter_Copies(childName));
if (name.Equals(childName)) {
PRBool childNameEquals = PR_FALSE;
child->NameEquals(aName, &childNameEquals);
if (childNameEquals) {
*_retval = child;
NS_ADDREF(*_retval);
break;