Bug 516085 - replace the most frequent IOService getter with an efficient one r=biesi

This commit is contained in:
Taras Glek 2010-04-12 08:44:28 -07:00
Родитель 8608d2611e
Коммит 119d09e697
3 изменённых файлов: 42 добавлений и 7 удалений

Просмотреть файл

@ -381,7 +381,7 @@ static PRBool
URIIsLocalFile(nsIURI *aURI)
{
PRBool isFile;
nsCOMPtr<nsINetUtil> util = do_GetIOService();
nsCOMPtr<nsINetUtil> util = do_GetNetUtil();
return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
nsIProtocolHandler::URI_IS_LOCAL_FILE,

Просмотреть файл

@ -10647,7 +10647,7 @@ PRBool
nsDocShell::URIIsLocalFile(nsIURI *aURI)
{
PRBool isFile;
nsCOMPtr<nsINetUtil> util = do_GetIOService();
nsCOMPtr<nsINetUtil> util = do_GetNetUtil();
return util && NS_SUCCEEDED(util->ProtocolHasFlags(aURI,
nsIProtocolHandler::URI_IS_LOCAL_FILE,

Просмотреть файл

@ -23,6 +23,7 @@
* Contributor(s):
* Bradley Baetz <bbaetz@student.usyd.edu.au>
* Malcolm Smith <malsmith@cs.rmit.edu.au>
* Taras Glek <tglek@mozilla.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
@ -101,7 +102,32 @@
#include "nsIIDNService.h"
#include "nsIChannelEventSink.h"
#include "nsIChannelPolicy.h"
#include "mozilla/Services.h"
#ifdef MOZILLA_INTERNAL_API
inline already_AddRefed<nsIIOService>
do_GetIOService(nsresult* error = 0)
{
already_AddRefed<nsIIOService> ret = mozilla::services::GetIOService();
if (error)
*error = ret.get() ? NS_OK : NS_ERROR_FAILURE;
return ret;
}
inline already_AddRefed<nsINetUtil>
do_GetNetUtil(nsresult *error = 0)
{
nsCOMPtr<nsIIOService> io = mozilla::services::GetIOService();
already_AddRefed<nsINetUtil> ret = nsnull;
if (io)
CallQueryInterface(io, &ret.mRawPtr);
if (error)
*error = ret.get() ? NS_OK : NS_ERROR_FAILURE;
return ret;
}
#else
// Helper, to simplify getting the I/O service.
inline const nsGetServiceByContractIDWithError
do_GetIOService(nsresult* error = 0)
@ -109,6 +135,14 @@ do_GetIOService(nsresult* error = 0)
return nsGetServiceByContractIDWithError(NS_IOSERVICE_CONTRACTID, error);
}
// An alias to do_GetIOService
inline const nsGetServiceByContractIDWithError
do_GetNetUtil(nsresult* error = 0)
{
return do_GetIOService(error);
}
#endif
// private little helper function... don't call this directly!
inline nsresult
net_EnsureIOService(nsIIOService **ios, nsCOMPtr<nsIIOService> &grip)
@ -878,7 +912,7 @@ NS_ParseContentType(const nsACString &rawContentType,
{
// contentCharset is left untouched if not present in rawContentType
nsresult rv;
nsCOMPtr<nsINetUtil> util = do_GetIOService(&rv);
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCString charset;
PRBool hadCharset;
@ -898,7 +932,7 @@ NS_ExtractCharsetFromContentType(const nsACString &rawContentType,
{
// contentCharset is left untouched if not present in rawContentType
nsresult rv;
nsCOMPtr<nsINetUtil> util = do_GetIOService(&rv);
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
NS_ENSURE_SUCCESS(rv, rv);
return util->ExtractCharsetFromContentType(rawContentType,
@ -1431,10 +1465,11 @@ NS_TryToMakeImmutable(nsIURI* uri,
nsresult* outRv = nsnull)
{
nsresult rv;
nsCOMPtr<nsINetUtil> util = do_GetIOService(&rv);
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
nsIURI* result = nsnull;
if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(util, "do_GetIOService lied");
NS_ASSERTION(util, "do_GetNetUtil lied");
rv = util->ToImmutableURI(uri, &result);
}
@ -1459,7 +1494,7 @@ NS_URIChainHasFlags(nsIURI *uri,
PRBool *result)
{
nsresult rv;
nsCOMPtr<nsINetUtil> util = do_GetIOService(&rv);
nsCOMPtr<nsINetUtil> util = do_GetNetUtil(&rv);
NS_ENSURE_SUCCESS(rv, rv);
return util->URIChainHasFlags(uri, flags, result);