Bug 1143651 - don't use CallQueryInterface when the compiler can do the cast for us; r=ehsan

This commit is contained in:
Nathan Froyd 2015-03-12 13:20:29 -04:00
parent 6a1aeb9960
commit 4c7234747e
22 changed files with 80 additions and 83 deletions

View File

@ -1801,13 +1801,10 @@ nsSHistory::SetRootDocShell(nsIDocShell * aDocShell)
NS_IMETHODIMP NS_IMETHODIMP
nsSHistory::GetSHistoryEnumerator(nsISimpleEnumerator** aEnumerator) nsSHistory::GetSHistoryEnumerator(nsISimpleEnumerator** aEnumerator)
{ {
nsresult status = NS_OK;
NS_ENSURE_ARG_POINTER(aEnumerator); NS_ENSURE_ARG_POINTER(aEnumerator);
nsSHEnumerator * iterator = new nsSHEnumerator(this); nsRefPtr<nsSHEnumerator> iterator = new nsSHEnumerator(this);
if (iterator && NS_FAILED(status = CallQueryInterface(iterator, aEnumerator))) iterator.forget(aEnumerator);
delete iterator; return NS_OK;
return status;
} }

View File

@ -46,7 +46,8 @@ MultipartFileImpl::GetInternalStream(nsIInputStream** aStream)
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
return CallQueryInterface(stream, aStream); stream.forget(aStream);
return NS_OK;
} }
already_AddRefed<FileImpl> already_AddRefed<FileImpl>

View File

@ -2499,7 +2499,9 @@ nsFrameLoader::GetMessageManager(nsIMessageSender** aManager)
{ {
EnsureMessageManager(); EnsureMessageManager();
if (mMessageManager) { if (mMessageManager) {
CallQueryInterface(mMessageManager, aManager); nsRefPtr<nsFrameMessageManager> mm(mMessageManager);
mm.forget(aManager);
return NS_OK;
} }
return NS_OK; return NS_OK;
} }

View File

@ -1490,11 +1490,12 @@ NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult)
{ {
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default, NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default,
NS_ERROR_NOT_AVAILABLE); NS_ERROR_NOT_AVAILABLE);
nsFrameMessageManager* mm = new nsFrameMessageManager(nullptr, nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
nullptr, nullptr,
MM_CHROME | MM_GLOBAL | MM_BROADCASTER); MM_CHROME | MM_GLOBAL | MM_BROADCASTER);
RegisterStrongMemoryReporter(new MessageManagerReporter()); RegisterStrongMemoryReporter(new MessageManagerReporter());
return CallQueryInterface(mm, aResult); mm.forget(aResult);
return NS_OK;
} }
nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>* nsDataHashtable<nsStringHashKey, nsMessageManagerScriptHolder*>*
@ -2008,7 +2009,8 @@ NS_NewParentProcessMessageManager(nsIMessageBroadcaster** aResult)
MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER); MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER);
nsFrameMessageManager::sParentProcessManager = mm; nsFrameMessageManager::sParentProcessManager = mm;
nsFrameMessageManager::NewProcessMessageManager(false); // Create same process message manager. nsFrameMessageManager::NewProcessMessageManager(false); // Create same process message manager.
return CallQueryInterface(mm, aResult); mm.forget(aResult);
return NS_OK;
} }
@ -2055,9 +2057,10 @@ NS_NewChildProcessMessageManager(nsISyncMessageSender** aResult)
nullptr, nullptr,
MM_PROCESSMANAGER | MM_OWNSCALLBACK); MM_PROCESSMANAGER | MM_OWNSCALLBACK);
nsFrameMessageManager::SetChildProcessManager(mm); nsFrameMessageManager::SetChildProcessManager(mm);
ProcessGlobal* global = new ProcessGlobal(mm); nsRefPtr<ProcessGlobal> global = new ProcessGlobal(mm);
NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(global->Init(), NS_ERROR_UNEXPECTED);
return CallQueryInterface(global, aResult); global.forget(aResult);
return NS_OK;
} }

View File

@ -40,14 +40,12 @@
using namespace mozilla::dom; using namespace mozilla::dom;
nsresult NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer) nsresult
NS_NewHTMLContentSerializer(nsIContentSerializer** aSerializer)
{ {
nsHTMLContentSerializer* it = new nsHTMLContentSerializer(); nsRefPtr<nsHTMLContentSerializer> it = new nsHTMLContentSerializer();
if (!it) { it.forget(aSerializer);
return NS_ERROR_OUT_OF_MEMORY; return NS_OK;
}
return CallQueryInterface(it, aSerializer);
} }
nsHTMLContentSerializer::nsHTMLContentSerializer() nsHTMLContentSerializer::nsHTMLContentSerializer()

View File

@ -54,14 +54,12 @@ static int32_t GetUnicharStringWidth(const char16_t* pwcs, int32_t n);
static const uint32_t TagStackSize = 500; static const uint32_t TagStackSize = 500;
static const uint32_t OLStackSize = 100; static const uint32_t OLStackSize = 100;
nsresult NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer) nsresult
NS_NewPlainTextSerializer(nsIContentSerializer** aSerializer)
{ {
nsPlainTextSerializer* it = new nsPlainTextSerializer(); nsRefPtr<nsPlainTextSerializer> it = new nsPlainTextSerializer();
if (!it) { it.forget(aSerializer);
return NS_ERROR_OUT_OF_MEMORY; return NS_OK;
}
return CallQueryInterface(it, aSerializer);
} }
nsPlainTextSerializer::nsPlainTextSerializer() nsPlainTextSerializer::nsPlainTextSerializer()

View File

@ -40,14 +40,12 @@ static const int32_t kLongLineLen = 128;
#define kXMLNS "xmlns" #define kXMLNS "xmlns"
nsresult NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer) nsresult
NS_NewXHTMLContentSerializer(nsIContentSerializer** aSerializer)
{ {
nsXHTMLContentSerializer* it = new nsXHTMLContentSerializer(); nsRefPtr<nsXHTMLContentSerializer> it = new nsXHTMLContentSerializer();
if (!it) { it.forget(aSerializer);
return NS_ERROR_OUT_OF_MEMORY; return NS_OK;
}
return CallQueryInterface(it, aSerializer);
} }
nsXHTMLContentSerializer::nsXHTMLContentSerializer() nsXHTMLContentSerializer::nsXHTMLContentSerializer()

View File

@ -43,14 +43,12 @@ using namespace mozilla::dom;
#define INDENT_STRING " " #define INDENT_STRING " "
#define INDENT_STRING_LENGTH 2 #define INDENT_STRING_LENGTH 2
nsresult NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer) nsresult
NS_NewXMLContentSerializer(nsIContentSerializer** aSerializer)
{ {
nsXMLContentSerializer* it = new nsXMLContentSerializer(); nsRefPtr<nsXMLContentSerializer> it = new nsXMLContentSerializer();
if (!it) { it.forget(aSerializer);
return NS_ERROR_OUT_OF_MEMORY; return NS_OK;
}
return CallQueryInterface(it, aSerializer);
} }
nsXMLContentSerializer::nsXMLContentSerializer() nsXMLContentSerializer::nsXMLContentSerializer()

View File

@ -1910,7 +1910,7 @@ HTMLInputElement::GetList(nsIDOMHTMLElement** aValue)
return NS_OK; return NS_OK;
} }
CallQueryInterface(element, aValue); element.forget(aValue);
return NS_OK; return NS_OK;
} }

View File

@ -38,13 +38,12 @@ NS_NewXBLContentSink(nsIXMLContentSink** aResult,
{ {
NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_ARG_POINTER(aResult);
nsXBLContentSink* it = new nsXBLContentSink(); nsRefPtr<nsXBLContentSink> it = new nsXBLContentSink();
nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
nsresult rv = it->Init(aDoc, aURI, aContainer); nsresult rv = it->Init(aDoc, aURI, aContainer);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(it, aResult); it.forget(aResult);
return NS_OK;
} }
nsXBLContentSink::nsXBLContentSink() nsXBLContentSink::nsXBLContentSink()

View File

@ -86,13 +86,13 @@ NS_NewXMLContentSink(nsIXMLContentSink** aResult,
if (nullptr == aResult) { if (nullptr == aResult) {
return NS_ERROR_NULL_POINTER; return NS_ERROR_NULL_POINTER;
} }
nsXMLContentSink* it = new nsXMLContentSink(); nsRefPtr<nsXMLContentSink> it = new nsXMLContentSink();
nsCOMPtr<nsIXMLContentSink> kungFuDeathGrip = it;
nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel); nsresult rv = it->Init(aDoc, aURI, aContainer, aChannel);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(it, aResult); it.forget(aResult);
return NS_OK;
} }
nsXMLContentSink::nsXMLContentSink() nsXMLContentSink::nsXMLContentSink()

View File

@ -172,7 +172,7 @@ nsXULCommandDispatcher::GetFocusedWindow(nsIDOMWindow** aWindow)
if (domdoc && !nsContentUtils::CanCallerAccess(domdoc)) if (domdoc && !nsContentUtils::CanCallerAccess(domdoc))
return NS_ERROR_DOM_SECURITY_ERR; return NS_ERROR_DOM_SECURITY_ERR;
CallQueryInterface(window, aWindow); window.forget(aWindow);
return NS_OK; return NS_OK;
} }

View File

@ -1314,14 +1314,14 @@ nsXULTemplateQueryProcessorRDF::ParseLiteral(const nsString& aParseType,
rv = gRDFService->GetIntLiteral(intValue, getter_AddRefs(intLiteral)); rv = gRDFService->GetIntLiteral(intValue, getter_AddRefs(intLiteral));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
rv = CallQueryInterface(intLiteral, aResult); intLiteral.forget(aResult);
} }
else { else {
nsCOMPtr<nsIRDFLiteral> literal; nsCOMPtr<nsIRDFLiteral> literal;
rv = gRDFService->GetLiteral(aValue.get(), getter_AddRefs(literal)); rv = gRDFService->GetLiteral(aValue.get(), getter_AddRefs(literal));
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
rv = CallQueryInterface(literal, aResult); literal.forget(aResult);
} }
return rv; return rv;
} }

View File

@ -141,7 +141,8 @@ static nsresult EncodeImageData(DataSourceSurface* aDataSurface,
aDataSurface->Unmap(); aDataSurface->Unmap();
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(encoder, aStream); encoder.forget(aStream);
return NS_OK;
} }
NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer, NS_IMETHODIMP imgTools::EncodeImage(imgIContainer *aContainer,

View File

@ -504,7 +504,8 @@ nsJARURI::Clone(nsIURI **result)
rv = CloneWithJARFileInternal(mJARFile, eHonorRef, getter_AddRefs(uri)); rv = CloneWithJARFileInternal(mJARFile, eHonorRef, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return CallQueryInterface(uri, result); uri.forget(result);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -516,7 +517,8 @@ nsJARURI::CloneIgnoringRef(nsIURI **result)
rv = CloneWithJARFileInternal(mJARFile, eIgnoreRef, getter_AddRefs(uri)); rv = CloneWithJARFileInternal(mJARFile, eIgnoreRef, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
return CallQueryInterface(uri, result); uri.forget(result);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -749,11 +749,9 @@ Preferences::GetBranch(const char *aPrefRoot, nsIPrefBranch **_retval)
if ((nullptr != aPrefRoot) && (*aPrefRoot != '\0')) { if ((nullptr != aPrefRoot) && (*aPrefRoot != '\0')) {
// TODO: - cache this stuff and allow consumers to share branches (hold weak references I think) // TODO: - cache this stuff and allow consumers to share branches (hold weak references I think)
nsPrefBranch* prefBranch = new nsPrefBranch(aPrefRoot, false); nsRefPtr<nsPrefBranch> prefBranch = new nsPrefBranch(aPrefRoot, false);
if (!prefBranch) prefBranch.forget(_retval);
return NS_ERROR_OUT_OF_MEMORY; rv = NS_OK;
rv = CallQueryInterface(prefBranch, _retval);
} else { } else {
// special case caching the default root // special case caching the default root
nsCOMPtr<nsIPrefBranch> root(sRootBranch); nsCOMPtr<nsIPrefBranch> root(sRootBranch);

View File

@ -289,7 +289,8 @@ nsresult AndroidCaptureProvider::Init(nsACString& aContentType,
} else { } else {
NS_NOTREACHED("Should not have asked Android for this type!"); NS_NOTREACHED("Should not have asked Android for this type!");
} }
return CallQueryInterface(stream, aStream); stream.forget(aStream);
return NS_OK;
} }
already_AddRefed<AndroidCaptureProvider> GetAndroidCaptureProvider() { already_AddRefed<AndroidCaptureProvider> GetAndroidCaptureProvider() {

View File

@ -50,7 +50,8 @@ nsDeviceProtocolHandler::NewURI(const nsACString &spec,
nsresult rv = uri->SetSpec(spec); nsresult rv = uri->SetSpec(spec);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(uri, result); uri.forget(result);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -66,7 +67,8 @@ nsDeviceProtocolHandler::NewChannel2(nsIURI* aURI,
rv = channel->SetLoadInfo(aLoadInfo); rv = channel->SetLoadInfo(aLoadInfo);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
return CallQueryInterface(channel, aResult); channel.forget(aResult);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP

View File

@ -237,10 +237,9 @@ nsResProtocolHandler::NewURI(const nsACString &aSpec,
{ {
nsresult rv; nsresult rv;
nsResURL *resURL = new nsResURL(); nsRefPtr<nsResURL> resURL = new nsResURL();
if (!resURL) if (!resURL)
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(resURL);
// unescape any %2f and %2e to make sure nsStandardURL coalesces them. // unescape any %2f and %2e to make sure nsStandardURL coalesces them.
// Later net_GetFileFromURLSpec() will do a full unescape and we want to // Later net_GetFileFromURLSpec() will do a full unescape and we want to
@ -272,9 +271,9 @@ nsResProtocolHandler::NewURI(const nsACString &aSpec,
spec.Append(last, src-last); spec.Append(last, src-last);
rv = resURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI); rv = resURL->Init(nsIStandardURL::URLTYPE_STANDARD, -1, spec, aCharset, aBaseURI);
if (NS_SUCCEEDED(rv)) if (NS_SUCCEEDED(rv)) {
rv = CallQueryInterface(resURL, result); resURL.forget(result);
NS_RELEASE(resURL); }
return rv; return rv;
} }

View File

@ -4,7 +4,7 @@
#include "pk11func.h" #include "pk11func.h"
#include "mozilla/DebugOnly.h" #include "mozilla/DebugOnly.h"
#include "mozilla/RefPtr.h" #include "nsRefPtr.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "PSMRunnable.h" #include "PSMRunnable.h"
#include "nsString.h" #include "nsString.h"
@ -84,13 +84,14 @@ NS_IMETHODIMP nsProtectedAuthThread::GetTokenName(nsAString &_retval)
NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval) NS_IMETHODIMP nsProtectedAuthThread::GetSlot(nsIPKCS11Slot **_retval)
{ {
RefPtr<nsPKCS11Slot> slot; nsRefPtr<nsPKCS11Slot> slot;
{ {
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
slot = new nsPKCS11Slot(mSlot); slot = new nsPKCS11Slot(mSlot);
} }
return CallQueryInterface (slot.get(), _retval); slot.forget(_retval);
return NS_OK;
} }
void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot) void nsProtectedAuthThread::SetParams(PK11SlotInfo* aSlot)

View File

@ -221,15 +221,14 @@ nsWindowMediator::GetZOrderDOMWindowEnumerator(
NS_ENSURE_ARG_POINTER(_retval); NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_STATE(mReady); NS_ENSURE_STATE(mReady);
nsAppShellWindowEnumerator *enumerator; nsRefPtr<nsAppShellWindowEnumerator> enumerator;
if (aFrontToBack) if (aFrontToBack)
enumerator = new nsASDOMWindowFrontToBackEnumerator(aWindowType, *this); enumerator = new nsASDOMWindowFrontToBackEnumerator(aWindowType, *this);
else else
enumerator = new nsASDOMWindowBackToFrontEnumerator(aWindowType, *this); enumerator = new nsASDOMWindowBackToFrontEnumerator(aWindowType, *this);
if (enumerator)
return CallQueryInterface(enumerator, _retval);
return NS_ERROR_OUT_OF_MEMORY; enumerator.forget(_retval);
return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -241,15 +240,14 @@ nsWindowMediator::GetZOrderXULWindowEnumerator(
NS_ENSURE_ARG_POINTER(_retval); NS_ENSURE_ARG_POINTER(_retval);
NS_ENSURE_STATE(mReady); NS_ENSURE_STATE(mReady);
nsAppShellWindowEnumerator *enumerator; nsRefPtr<nsAppShellWindowEnumerator> enumerator;
if (aFrontToBack) if (aFrontToBack)
enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this); enumerator = new nsASXULWindowFrontToBackEnumerator(aWindowType, *this);
else else
enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this); enumerator = new nsASXULWindowBackToFrontEnumerator(aWindowType, *this);
if (enumerator)
return CallQueryInterface(enumerator, _retval);
return NS_ERROR_OUT_OF_MEMORY; enumerator.forget(_retval);
return NS_OK;
} }
int32_t int32_t

View File

@ -365,7 +365,8 @@ NS_IMETHODIMP nsWindowDataSource::GetTarget(nsIRDFResource *aSource, nsIRDFResou
if (NS_FAILED(rv)) return(rv); if (NS_FAILED(rv)) return(rv);
if (!indexInt) return(NS_ERROR_FAILURE); if (!indexInt) return(NS_ERROR_FAILURE);
return CallQueryInterface(indexInt, _retval); indexInt.forget(_retval);
return NS_OK;
} }
return mInner->GetTarget(aSource, aProperty, aTruthValue, _retval); return mInner->GetTarget(aSource, aProperty, aTruthValue, _retval);