зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
adb0600bb7
Коммит
7b38117f01
|
@ -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;
|
||||
|
|
|
@ -39,6 +39,15 @@ interface nsIDocShellTreeItem : nsISupports
|
|||
*/
|
||||
attribute wstring name;
|
||||
|
||||
/**
|
||||
* Compares the provided name against the item's name and
|
||||
* returns the appropriate result.
|
||||
*
|
||||
* @return <CODE>PR_TRUE</CODE> if names match;
|
||||
* <CODE>PR_FALSE</CODE> otherwise.
|
||||
*/
|
||||
boolean nameEquals(in wstring name);
|
||||
|
||||
/*
|
||||
Definitions for the item types.
|
||||
*/
|
||||
|
|
|
@ -397,6 +397,22 @@ NS_IMETHODIMP nsWebBrowser::SetName(const PRUnichar* aName)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::NameEquals(const PRUnichar *aName, PRBool *_retval)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aName);
|
||||
NS_ENSURE_ARG_POINTER(_retval);
|
||||
if(mDocShell)
|
||||
{
|
||||
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(mDocShell));
|
||||
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
||||
return docShellAsItem->NameEquals(aName, _retval);
|
||||
}
|
||||
else
|
||||
*_retval = mInitInfo->name.Equals(aName);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsWebBrowser::GetItemType(PRInt32* aItemType)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aItemType);
|
||||
|
|
Загрузка…
Ссылка в новой задаче