Bug 1489503 - In docShell, don't set the same title a second time. r=bzbarsky

This avoids setting the title a second time when the title and uri remain the same across setTitle calls. This means we can avoid unnecessary history updates which currently result in extra disk i/o.

Differential Revision: https://phabricator.services.mozilla.com/D5431
This commit is contained in:
Mark Banner
2018-09-29 07:55:16 +00:00
parent cc3f652a32
commit 38f9a15a1f
2 changed files with 17 additions and 0 deletions

View File

@@ -384,6 +384,7 @@ nsDocShell::nsDocShell()
, mInvisible(false)
, mHasLoadedNonBlankURI(false)
, mBlankTiming(false)
, mTitleValidForCurrentURI(false)
{
mHistoryID.m0 = 0;
mHistoryID.m1 = 0;
@@ -1331,6 +1332,12 @@ nsDocShell::SetCurrentURI(nsIURI* aURI, nsIRequest* aRequest,
return false;
}
bool uriIsEqual = false;
if (!mCurrentURI || !aURI ||
NS_FAILED(mCurrentURI->Equals(aURI, &uriIsEqual)) || !uriIsEqual) {
mTitleValidForCurrentURI = false;
}
mCurrentURI = aURI;
if (!NS_IsAboutBlank(mCurrentURI)) {
@@ -5986,8 +5993,15 @@ nsDocShell::GetTitle(nsAString& aTitle)
NS_IMETHODIMP
nsDocShell::SetTitle(const nsAString& aTitle)
{
// Avoid unnecessary updates of the title if the URI and the title haven't
// changed.
if (mTitleValidForCurrentURI && mTitle == aTitle) {
return NS_OK;
}
// Store local title
mTitle = aTitle;
mTitleValidForCurrentURI = true;
nsCOMPtr<nsIDocShellTreeItem> parent;
GetSameTypeParent(getter_AddRefs(parent));