Bug 1525208 - Part 8: Avoid the overhead of calling NS_GetInnermostURI() in nsEffectiveTLDService; r=baku

Depends on D18649

Differential Revision: https://phabricator.services.mozilla.com/D18650

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Ehsan Akhgari 2019-02-05 18:12:03 +00:00
parent 385db59f90
commit 5693611ad4
2 changed files with 48 additions and 12 deletions

View File

@ -12,10 +12,12 @@
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsILoadGroup.h"
#include "nsINestedURI.h"
#include "nsINetUtil.h"
#include "nsIRequest.h"
#include "nsILoadInfo.h"
#include "nsIIOService.h"
#include "nsIURI.h"
#include "mozilla/NotNull.h"
#include "mozilla/Services.h"
#include "mozilla/Unused.h"
@ -24,7 +26,6 @@
#include "nsServiceManagerUtils.h"
#include "nsString.h"
class nsIURI;
class nsIPrincipal;
class nsIAsyncStreamCopier;
class nsIAuthPrompt;
@ -38,7 +39,6 @@ class nsIFileStream;
class nsIInputStream;
class nsIInputStreamPump;
class nsIInterfaceRequestor;
class nsINestedURI;
class nsIOutputStream;
class nsIParentChannel;
class nsIPersistentProperties;
@ -717,6 +717,44 @@ nsresult NS_URIChainHasFlags(nsIURI *uri, uint32_t flags, bool *result);
*/
already_AddRefed<nsIURI> NS_GetInnermostURI(nsIURI *aURI);
/**
* Helper function for getting the host name of the innermost URI for a given
* URI. The return value could be the host name of the URI passed in if it's
* not a nested URI.
*/
inline nsresult NS_GetInnermostURIHost(nsIURI *aURI, nsACString &aHost) {
aHost.Truncate();
// This block is optimized in order to avoid the overhead of calling
// NS_GetInnermostURI() which incurs a lot of overhead in terms of
// AddRef/Release calls.
nsINestedURI *nestedURI = nullptr;
nsresult rv = CallQueryInterface(aURI, &nestedURI);
if (NS_SUCCEEDED(rv)) {
// We have a nested URI!
nsCOMPtr<nsIURI> uri;
rv = nestedURI->GetInnermostURI(getter_AddRefs(uri));
if (NS_FAILED(rv)) {
return rv;
}
NS_RELEASE(nestedURI);
rv = uri->GetAsciiHost(aHost);
if (NS_FAILED(rv)) {
return rv;
}
} else {
// We have a non-nested URI!
rv = aURI->GetAsciiHost(aHost);
if (NS_FAILED(rv)) {
return rv;
}
}
return NS_OK;
}
/**
* Get the "final" URI for a channel. This is either channel's load info
* resultPrincipalURI, if set, or GetOriginalURI. In most cases (but not all)

View File

@ -110,12 +110,11 @@ nsEffectiveTLDService::GetPublicSuffix(nsIURI *aURI,
nsACString &aPublicSuffix) {
NS_ENSURE_ARG_POINTER(aURI);
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
NS_ENSURE_ARG_POINTER(innerURI);
nsAutoCString host;
nsresult rv = innerURI->GetAsciiHost(host);
if (NS_FAILED(rv)) return rv;
nsresult rv = NS_GetInnermostURIHost(aURI, host);
if (NS_FAILED(rv)) {
return rv;
}
return GetBaseDomainInternal(host, 0, aPublicSuffix);
}
@ -129,12 +128,11 @@ nsEffectiveTLDService::GetBaseDomain(nsIURI *aURI, uint32_t aAdditionalParts,
NS_ENSURE_ARG_POINTER(aURI);
NS_ENSURE_TRUE(((int32_t)aAdditionalParts) >= 0, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIURI> innerURI = NS_GetInnermostURI(aURI);
NS_ENSURE_ARG_POINTER(innerURI);
nsAutoCString host;
nsresult rv = innerURI->GetAsciiHost(host);
if (NS_FAILED(rv)) return rv;
nsresult rv = NS_GetInnermostURIHost(aURI, host);
if (NS_FAILED(rv)) {
return rv;
}
return GetBaseDomainInternal(host, aAdditionalParts + 1, aBaseDomain);
}