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

Calling QueryInterface with a statically known IID should typically not
be necessary.  In those cases where it's not, the compiler can do the
cast for us, though we have to supply the reference-counting that
QueryInterface would do.

In passing, several redundant null-checks for the result of |new T| have
been deleted.
This commit is contained in:
Nathan Froyd 2015-03-12 09:43:50 -04:00
Родитель 46bf91f4be
Коммит b252a27930
13 изменённых файлов: 43 добавлений и 48 удалений

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

@ -385,9 +385,7 @@ nsComposerCommandsUpdater::Notify(nsITimer *timer)
nsresult
NS_NewComposerCommandsUpdater(nsISelectionListener** aInstancePtrResult)
{
nsComposerCommandsUpdater* newThang = new nsComposerCommandsUpdater;
NS_ENSURE_TRUE(newThang, NS_ERROR_OUT_OF_MEMORY);
return newThang->QueryInterface(NS_GET_IID(nsISelectionListener),
(void **)aInstancePtrResult);
nsRefPtr<nsComposerCommandsUpdater> newThang = new nsComposerCommandsUpdater;
newThang.forget(aInstancePtrResult);
return NS_OK;
}

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

@ -254,7 +254,7 @@ nsresult NS_NewHTMLURIRefObject(nsIURIRefObject** aResult, nsIDOMNode* aNode)
*aResult = 0;
return rv;
}
return refObject->QueryInterface(NS_GET_IID(nsIURIRefObject),
(void**)aResult);
refObject.forget(aResult);
return NS_OK;
}

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

@ -2000,7 +2000,7 @@ nsTextServicesDocument::GetDocumentContentRootNode(nsIDOMNode **aNode)
NS_ENSURE_TRUE(bodyElement, NS_ERROR_FAILURE);
result = bodyElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
bodyElement.forget(aNode);
}
else
{
@ -2014,7 +2014,7 @@ nsTextServicesDocument::GetDocumentContentRootNode(nsIDOMNode **aNode)
NS_ENSURE_TRUE(docElement, NS_ERROR_FAILURE);
result = docElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
docElement.forget(aNode);
}
return result;

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

@ -288,10 +288,10 @@ nsControllerCommandGroup::IsCommandInGroup(const char *aCommand, const char *aGr
NS_IMETHODIMP
nsControllerCommandGroup::GetGroupsEnumerator(nsISimpleEnumerator **_retval)
{
nsGroupsEnumerator *groupsEnum = new nsGroupsEnumerator(mGroupsHash);
if (!groupsEnum) return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsGroupsEnumerator> groupsEnum = new nsGroupsEnumerator(mGroupsHash);
return groupsEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void **)_retval);
groupsEnum.forget(_retval);
return NS_OK;
}
/* nsISimpleEnumerator getEnumeratorForGroup (in DOMString aGroup); */
@ -301,10 +301,10 @@ nsControllerCommandGroup::GetEnumeratorForGroup(const char *aGroup, nsISimpleEnu
nsDependentCString groupKey(aGroup);
nsTArray<nsCString> *commandList = mGroupsHash.Get(groupKey); // may be null
nsNamedGroupEnumerator *theGroupEnum = new nsNamedGroupEnumerator(commandList);
if (!theGroupEnum) return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsNamedGroupEnumerator> theGroupEnum = new nsNamedGroupEnumerator(commandList);
return theGroupEnum->QueryInterface(NS_GET_IID(nsISimpleEnumerator), (void **)_retval);
theGroupEnum.forget(_retval);
return NS_OK;
}
#if 0

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

@ -409,8 +409,8 @@ nsresult nsWebBrowserFind::GetRootNode(nsIDOMDocument* aDomDoc,
rv = htmlDoc->GetBody(getter_AddRefs(bodyElement));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG_POINTER(bodyElement);
return bodyElement->QueryInterface(NS_GET_IID(nsIDOMNode),
(void **)aNode);
bodyElement.forget(aNode);
return NS_OK;
}
// For non-HTML documents, the content root node will be the doc element.
@ -418,7 +418,8 @@ nsresult nsWebBrowserFind::GetRootNode(nsIDOMDocument* aDomDoc,
rv = aDomDoc->GetDocumentElement(getter_AddRefs(docElement));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_ARG_POINTER(docElement);
return docElement->QueryInterface(NS_GET_IID(nsIDOMNode), (void **)aNode);
docElement.forget(aNode);
return NS_OK;
}
nsresult nsWebBrowserFind::SetRangeAroundDocument(nsIDOMRange* aSearchRange,

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

@ -651,9 +651,8 @@ nsStringBundleService::CreateExtensibleBundle(const char* aCategory,
return res;
}
res = bundle->QueryInterface(NS_GET_IID(nsIStringBundle), (void**) aResult);
return res;
bundle.forget(aResult);
return NS_OK;
}
#define GLOBAL_PROPERTIES "chrome://global/locale/global-strres.properties"

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

@ -270,17 +270,13 @@ PSMContentListener::DoContent(const nsACString & aContentType,
nsIStreamListener ** aContentHandler,
bool * aAbortProcess)
{
PSMContentDownloader *downLoader;
uint32_t type;
type = getPSMContentType(PromiseFlatCString(aContentType).get());
PR_LOG(gPIPNSSLog, PR_LOG_DEBUG, ("PSMContentListener::DoContent\n"));
if (type != PSMContentDownloader::UNKNOWN_TYPE) {
downLoader = new PSMContentDownloader(type);
if (downLoader) {
downLoader->QueryInterface(NS_GET_IID(nsIStreamListener),
(void **)aContentHandler);
return NS_OK;
}
nsRefPtr<PSMContentDownloader> downLoader = new PSMContentDownloader(type);
downLoader.forget(aContentHandler);
return NS_OK;
}
return NS_ERROR_FAILURE;
}

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

@ -4323,8 +4323,9 @@ nsNavHistoryResult::GetRoot(nsINavHistoryContainerResultNode** aRoot)
*aRoot = nullptr;
return NS_ERROR_FAILURE;
}
return mRootNode->QueryInterface(NS_GET_IID(nsINavHistoryContainerResultNode),
reinterpret_cast<void**>(aRoot));
nsRefPtr<nsNavHistoryContainerResultNode> node(mRootNode);
node.forget(aRoot);
return NS_OK;
}

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

@ -1110,8 +1110,9 @@ nsPrintSettings::GetPageRanges(nsTArray<int32_t> &aPages)
nsresult
nsPrintSettings::_Clone(nsIPrintSettings **_retval)
{
nsPrintSettings* printSettings = new nsPrintSettings(*this);
return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
nsRefPtr<nsPrintSettings> printSettings = new nsPrintSettings(*this);
printSettings.forget(_retval);
return NS_OK;
}
/* nsIPrintSettings clone (); */

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

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
@ -251,8 +251,9 @@ nsImageFromClipboard ::GetEncodedImageStream (unsigned char * aClipboardData, co
if (NS_SUCCEEDED(rv)){
rv = encoder->InitFromData(rgbData, 0, width, height, 3 * width /* RGB * # pixels in a row */,
imgIEncoder::INPUT_FORMAT_RGB, EmptyString());
if (NS_SUCCEEDED(rv))
encoder->QueryInterface(NS_GET_IID(nsIInputStream), (void **) aInputStream);
if (NS_SUCCEEDED(rv)) {
encoder.forget(aInputStream);
}
}
}
delete [] rgbData;

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

@ -118,8 +118,9 @@ NS_IMETHODIMP nsPrintSettingsWin::SetDevMode(DEVMODEW * aDevMode)
nsresult
nsPrintSettingsWin::_Clone(nsIPrintSettings **_retval)
{
nsPrintSettingsWin* printSettings = new nsPrintSettingsWin(*this);
return printSettings->QueryInterface(NS_GET_IID(nsIPrintSettings), (void**)_retval); // ref counts
nsRefPtr<nsPrintSettingsWin> printSettings = new nsPrintSettingsWin(*this);
printSettings.forget(_retval);
return NS_OK;
}
//-------------------------------------------

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

@ -228,7 +228,8 @@ nsAppFileLocationProvider::GetFile(const char* aProp, bool* aPersistent,
}
if (localFile && NS_SUCCEEDED(rv)) {
return localFile->QueryInterface(NS_GET_IID(nsIFile), (void**)aResult);
localFile.forget(aResult);
return NS_OK;
}
return rv;

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

@ -195,11 +195,9 @@ nsWindowMediator::GetEnumerator(const char16_t* inType, nsISimpleEnumerator** ou
NS_ENSURE_ARG_POINTER(outEnumerator);
NS_ENSURE_STATE(mReady);
nsAppShellWindowEnumerator *enumerator = new nsASDOMWindowEarlyToLateEnumerator(inType, *this);
if (enumerator)
return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsAppShellWindowEnumerator> enumerator = new nsASDOMWindowEarlyToLateEnumerator(inType, *this);
enumerator.forget(outEnumerator);
return NS_OK;
}
NS_IMETHODIMP
@ -209,11 +207,9 @@ nsWindowMediator::GetXULWindowEnumerator(const char16_t* inType, nsISimpleEnumer
NS_ENSURE_ARG_POINTER(outEnumerator);
NS_ENSURE_STATE(mReady);
nsAppShellWindowEnumerator *enumerator = new nsASXULWindowEarlyToLateEnumerator(inType, *this);
if (enumerator)
return enumerator->QueryInterface(NS_GET_IID(nsISimpleEnumerator) , (void**)outEnumerator);
return NS_ERROR_OUT_OF_MEMORY;
nsRefPtr<nsAppShellWindowEnumerator> enumerator = new nsASXULWindowEarlyToLateEnumerator(inType, *this);
enumerator.forget(outEnumerator);
return NS_OK;
}
NS_IMETHODIMP