Skip to content

Commit

Permalink
Bug 1493737 - Fix many trivial calls to do_QueryInterface r=smaug
Browse files Browse the repository at this point in the history
If class A is derived from class B, then an instance of class A can be
converted to B via a static cast, so a slower QI is not needed.

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

--HG--
extra : moz-landing-system : lando
  • Loading branch information
amccreight committed Oct 1, 2018
1 parent 9e3b348 commit 837f0af
Show file tree
Hide file tree
Showing 74 changed files with 117 additions and 135 deletions.
10 changes: 3 additions & 7 deletions docshell/base/nsDocShell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3832,7 +3832,7 @@ nsDocShell::AddChildSHEntryInternal(nsISHEntry* aCloneRef,
index, getter_AddRefs(currentHE));
NS_ENSURE_TRUE(currentHE, NS_ERROR_FAILURE);

nsCOMPtr<nsISHEntry> currentEntry(do_QueryInterface(currentHE));
nsCOMPtr<nsISHEntry> currentEntry(currentHE);
if (currentEntry) {
nsCOMPtr<nsISHEntry> nextEntry;
uint32_t cloneID = aCloneRef->GetID();
Expand Down Expand Up @@ -6631,11 +6631,7 @@ nsDocShell::SuspendRefreshURIs()

timer->Cancel();

nsCOMPtr<nsITimerCallback> rt = do_QueryInterface(callback);
NS_ASSERTION(rt,
"RefreshURIList timer callbacks should only be RefreshTimer objects");

mRefreshURIList->ReplaceElementAt(rt, i);
mRefreshURIList->ReplaceElementAt(callback, i);
}
}

Expand Down Expand Up @@ -9501,7 +9497,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
// In some cases the Open call doesn't actually result in a new
// window being opened. We can detect these cases by examining the
// document in |newWin|, if any.
nsCOMPtr<nsPIDOMWindowOuter> piNewWin = do_QueryInterface(newWin);
nsCOMPtr<nsPIDOMWindowOuter> piNewWin = newWin;
if (piNewWin) {
nsCOMPtr<nsIDocument> newDoc = piNewWin->GetExtantDoc();
if (!newDoc || newDoc->IsInitialDocument()) {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/DocGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ DocGroup::ReportPerformanceInfo()

// iterating on documents until we find the top window
for (const auto& document : *this) {
nsCOMPtr<nsIDocument> doc = do_QueryInterface(document);
nsCOMPtr<nsIDocument> doc = document;
MOZ_ASSERT(doc);
nsCOMPtr<nsIURI> docURI = doc->GetDocumentURI();
if (!docURI) {
Expand Down
2 changes: 1 addition & 1 deletion dom/base/EventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ EventSourceImpl::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
if (IsClosed()) {
return NS_ERROR_ABORT;
}
nsCOMPtr<nsIRequest> aOldRequest = do_QueryInterface(aOldChannel);
nsCOMPtr<nsIRequest> aOldRequest = aOldChannel;
MOZ_ASSERT(aOldRequest, "Redirect from a null request?");

nsresult rv = CheckHealthOfRequestCallback(aOldRequest);
Expand Down
4 changes: 2 additions & 2 deletions dom/base/ImageEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ ImageEncoder::ExtractDataInternal(const nsAString& aType,
}

if (NS_SUCCEEDED(rv)) {
imgStream = do_QueryInterface(aEncoder);
imgStream = aEncoder;
}
} else {
if (BufferSizeFromDimensions(aSize.width, aSize.height, 4) == 0) {
Expand Down Expand Up @@ -493,7 +493,7 @@ ImageEncoder::ExtractDataInternal(const nsAString& aType,
aOptions);
emptyCanvas->Unmap();
if (NS_SUCCEEDED(rv)) {
imgStream = do_QueryInterface(aEncoder);
imgStream = aEncoder;
}
}
NS_ENSURE_SUCCESS(rv, rv);
Expand Down
2 changes: 1 addition & 1 deletion dom/base/InProcessTabChildMessageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ InProcessTabChildMessageManager::ChromeOuterWindowID()
return 0;
}

nsCOMPtr<nsIDocShellTreeItem> item = do_QueryInterface(mDocShell);
nsCOMPtr<nsIDocShellTreeItem> item = mDocShell;
nsCOMPtr<nsIDocShellTreeItem> root;
nsresult rv = item->GetRootTreeItem(getter_AddRefs(root));
if (NS_WARN_IF(NS_FAILED(rv))) {
Expand Down
4 changes: 2 additions & 2 deletions dom/base/ScreenOrientation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ ScreenOrientation::LockDeviceOrientation(hal::ScreenOrientation aOrientation,
return false;
}

nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner()->GetDoc());
nsCOMPtr<EventTarget> target = GetOwner()->GetDoc();
// We need to register a listener so we learn when we leave fullscreen
// and when we will have to unlock the screen.
// This needs to be done before LockScreenOrientation call to make sure
Expand Down Expand Up @@ -404,7 +404,7 @@ ScreenOrientation::UnlockDeviceOrientation()
}

// Remove event listener in case of fullscreen lock.
nsCOMPtr<EventTarget> target = do_QueryInterface(GetOwner()->GetDoc());
nsCOMPtr<EventTarget> target = GetOwner()->GetDoc();
if (target) {
target->RemoveSystemEventListener(NS_LITERAL_STRING("fullscreenchange"),
mFullscreenListener,
Expand Down
2 changes: 1 addition & 1 deletion dom/base/nsContentPermissionHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ VisibilityChangeListener::RemoveListener()
return;
}

nsCOMPtr<EventTarget> target = do_QueryInterface(window->GetExtantDoc());
nsCOMPtr<EventTarget> target = window->GetExtantDoc();
if (target) {
target->RemoveSystemEventListener(NS_LITERAL_STRING(kVisibilityChange),
/* listener */ this,
Expand Down
6 changes: 3 additions & 3 deletions dom/base/nsFocusManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,11 +2367,11 @@ nsFocusManager::UpdateCaret(bool aMoveCaretToFocus,
// this is called when a document is focused or when the caretbrowsing
// preference is changed
nsCOMPtr<nsIDocShell> focusedDocShell = mFocusedWindow->GetDocShell();
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(focusedDocShell);
if (!dsti)
if (!focusedDocShell) {
return;
}

if (dsti->ItemType() == nsIDocShellTreeItem::typeChrome) {
if (focusedDocShell->ItemType() == nsIDocShellTreeItem::typeChrome) {
return; // Never browse with caret in chrome
}

Expand Down
3 changes: 1 addition & 2 deletions dom/base/nsHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ nsHistory::GetState(JSContext* aCx, JS::MutableHandle<JS::Value> aResult,
return;
}

nsCOMPtr<nsIDocument> doc =
do_QueryInterface(win->GetExtantDoc());
nsCOMPtr<nsIDocument> doc = win->GetExtantDoc();
if (!doc) {
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
return;
Expand Down
4 changes: 2 additions & 2 deletions dom/base/nsRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,7 @@ nsRange::CloneContents(ErrorResult& aRv)

// Place the cloned subtree into the cloned doc frag tree!

nsCOMPtr<nsINode> cloneNode = do_QueryInterface(clone);
nsCOMPtr<nsINode> cloneNode = clone;
if (closestAncestor)
{
// Append the subtree under closestAncestor since it is the
Expand Down Expand Up @@ -2652,7 +2652,7 @@ nsRange::InsertNode(nsINode& aNode, ErrorResult& aRv)
return;
}

referenceNode = do_QueryInterface(secondPart);
referenceNode = secondPart;
} else {
tChildList = tStartContainer->ChildNodes();

Expand Down
5 changes: 2 additions & 3 deletions dom/broadcastchannel/BroadcastChannelChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
ipc::StructuredCloneDataNoTransfers cloneData;
cloneData.BorrowFromClonedMessageDataForBackgroundChild(aData);

nsCOMPtr<DOMEventTargetHelper> helper = mBC;
nsCOMPtr<EventTarget> eventTarget = do_QueryInterface(helper);
nsCOMPtr<EventTarget> eventTarget = mBC;

// The object is going to be deleted soon. No notify is required.
if (!eventTarget) {
Expand All @@ -62,7 +61,7 @@ BroadcastChannelChild::RecvNotify(const ClonedMessageData& aData)
nsCOMPtr<nsIGlobalObject> globalObject;

if (NS_IsMainThread()) {
globalObject = do_QueryInterface(mBC->GetParentObject());
globalObject = mBC->GetParentObject();
} else {
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
MOZ_ASSERT(workerPrivate);
Expand Down
2 changes: 1 addition & 1 deletion dom/events/Event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Event::EnsureWebAccessibleRelatedTarget(EventTarget* aRelatedTarget)
if (content && content->ChromeOnlyAccess() &&
!nsContentUtils::CanAccessNativeAnon()) {
content = content->FindFirstNonChromeOnlyAccessContent();
relatedTarget = do_QueryInterface(content);
relatedTarget = content;
}

if (relatedTarget) {
Expand Down
2 changes: 1 addition & 1 deletion dom/events/EventDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ EventDispatcher::Dispatch(nsISupports* aTarget,
nsCOMPtr<nsIContent> content = do_QueryInterface(target);
if (content && content->IsInNativeAnonymousSubtree()) {
nsCOMPtr<EventTarget> newTarget =
do_QueryInterface(content->FindFirstNonChromeOnlyAccessContent());
content->FindFirstNonChromeOnlyAccessContent();
NS_ENSURE_STATE(newTarget);

aEvent->mOriginalTarget = target;
Expand Down
7 changes: 3 additions & 4 deletions dom/events/EventStateManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ EventStateManager::PreHandleEvent(nsPresContext* aPresContext,
}
++gMouseOrKeyboardEventCounter;

nsCOMPtr<nsINode> node = do_QueryInterface(aTargetContent);
nsCOMPtr<nsINode> node = aTargetContent;
if (node &&
(aEvent->mMessage == eKeyUp || aEvent->mMessage == eMouseUp ||
aEvent->mMessage == eWheel || aEvent->mMessage == eTouchEnd ||
Expand Down Expand Up @@ -874,7 +874,7 @@ EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
return;
}

nsCOMPtr<nsINode> node = do_QueryInterface(aTargetContent);
nsCOMPtr<nsINode> node = aTargetContent;
if (!node) {
return;
}
Expand Down Expand Up @@ -4206,8 +4206,7 @@ EventStateManager::DispatchMouseOrPointerEvent(WidgetMouseEvent* aMouseEvent,
NS_WARNING("Should have pointer locked element, but didn't.");
return nullptr;
}
nsCOMPtr<nsIContent> content = do_QueryInterface(pointerLockedElement);
return mPresContext->GetPrimaryFrameFor(content);
return mPresContext->GetPrimaryFrameFor(pointerLockedElement);
}

mCurrentTargetContent = nullptr;
Expand Down
3 changes: 1 addition & 2 deletions dom/file/FileReaderSync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ FileReaderSync::ConvertStream(nsIInputStream *aStream,
nsIConverterInputStream::DEFAULT_REPLACEMENT_CHARACTER);
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsIUnicharInputStream> unicharStream =
do_QueryInterface(converterStream);
nsCOMPtr<nsIUnicharInputStream> unicharStream = converterStream;
NS_ENSURE_TRUE(unicharStream, NS_ERROR_FAILURE);

uint32_t numChars;
Expand Down
4 changes: 2 additions & 2 deletions dom/html/ImageDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ ImageDocument::Destroy()
{
if (mImageContent) {
// Remove our event listener from the image content.
nsCOMPtr<EventTarget> target = do_QueryInterface(mImageContent);
nsCOMPtr<EventTarget> target = mImageContent;
target->RemoveEventListener(NS_LITERAL_STRING("load"), this, false);
target->RemoveEventListener(NS_LITERAL_STRING("click"), this, false);

Expand Down Expand Up @@ -286,7 +286,7 @@ ImageDocument::SetScriptGlobalObject(nsIScriptGlobalObject* aScriptGlobalObject)
CreateSyntheticDocument();
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to create synthetic document");

target = do_QueryInterface(mImageContent);
target = mImageContent;
target->AddEventListener(NS_LITERAL_STRING("load"), this, false);
target->AddEventListener(NS_LITERAL_STRING("click"), this, false);
}
Expand Down
2 changes: 1 addition & 1 deletion dom/ipc/ContentParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4882,7 +4882,7 @@ ContentParent::CommonCreateWindow(PBrowserParent* aThisTab,
TabParent* thisTabParent = TabParent::GetFrom(aThisTab);
nsCOMPtr<nsIContent> frame;
if (thisTabParent) {
frame = do_QueryInterface(thisTabParent->GetOwnerElement());
frame = thisTabParent->GetOwnerElement();

if (NS_WARN_IF(thisTabParent->IsMozBrowser())) {
return IPC_FAIL(this, "aThisTab is not a MozBrowser");
Expand Down
18 changes: 8 additions & 10 deletions dom/ipc/TabParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ TabParent::CacheFrameLoader(nsFrameLoader* aFrameLoader)
already_AddRefed<nsPIDOMWindowOuter>
TabParent::GetParentWindowOuter()
{
nsCOMPtr<nsIContent> frame = do_QueryInterface(GetOwnerElement());
nsCOMPtr<nsIContent> frame = GetOwnerElement();
if (!frame) {
return nullptr;
}
Expand Down Expand Up @@ -585,7 +585,7 @@ TabParent::RecvEvent(const RemoteDOMEvent& aEvent)
RefPtr<Event> event = aEvent.mEvent;
NS_ENSURE_TRUE(event, IPC_OK());

nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(mFrameElement);
nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
NS_ENSURE_TRUE(target, IPC_OK());

event->SetOwner(target);
Expand Down Expand Up @@ -1146,8 +1146,7 @@ TabParent::SendRealMouseEvent(WidgetMouseEvent& aEvent)
LayoutDeviceToCSSScale
TabParent::GetLayoutDeviceToCSSScale()
{
nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
nsIDocument* doc = (content ? content->OwnerDoc() : nullptr);
nsIDocument* doc = (mFrameElement ? mFrameElement->OwnerDoc() : nullptr);
nsPresContext* ctx = (doc ? doc->GetPresContext() : nullptr);
return LayoutDeviceToCSSScale(ctx
? (float)ctx->AppUnitsPerDevPixel() / AppUnitsPerCSSPixel()
Expand Down Expand Up @@ -2028,8 +2027,7 @@ TabParent::RecvRequestFocus(const bool& aCanRaise)
return IPC_OK();
}

nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
if (!content || !content->OwnerDoc()) {
if (!mFrameElement || !mFrameElement->OwnerDoc()) {
return IPC_OK();
}

Expand Down Expand Up @@ -2485,7 +2483,7 @@ TabParent::RecvSetInputContext(
already_AddRefed<nsIWidget>
TabParent::GetTopLevelWidget()
{
nsCOMPtr<nsIContent> content = do_QueryInterface(mFrameElement);
nsCOMPtr<nsIContent> content = mFrameElement;
if (content) {
nsIPresShell* shell = content->OwnerDoc()->GetShell();
if (shell) {
Expand Down Expand Up @@ -2566,7 +2564,7 @@ TabParent::GetAuthPrompt(uint32_t aPromptReason, const nsIID& iid,
NS_ENSURE_SUCCESS(rv, rv);

nsCOMPtr<nsPIDOMWindowOuter> window;
nsCOMPtr<nsIContent> frame = do_QueryInterface(mFrameElement);
nsCOMPtr<nsIContent> frame = mFrameElement;
if (frame)
window = frame->OwnerDoc()->GetWindow();

Expand Down Expand Up @@ -3080,7 +3078,7 @@ TabParent::LayerTreeUpdate(const LayersObserverEpoch& aEpoch, bool aActive)
return;
}

nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(mFrameElement);
nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
if (!target) {
NS_WARNING("Could not locate target for layer tree message.");
return;
Expand Down Expand Up @@ -3113,7 +3111,7 @@ TabParent::RecvPaintWhileInterruptingJSNoOp(const LayersObserverEpoch& aEpoch)
mozilla::ipc::IPCResult
TabParent::RecvRemotePaintIsReady()
{
nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(mFrameElement);
nsCOMPtr<mozilla::dom::EventTarget> target = mFrameElement;
if (!target) {
NS_WARNING("Could not locate target for MozAfterRemotePaint message.");
return IPC_OK();
Expand Down
2 changes: 1 addition & 1 deletion dom/media/eme/MediaKeySession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ MediaKeySession::Token() const
already_AddRefed<DetailedPromise>
MediaKeySession::MakePromise(ErrorResult& aRv, const nsACString& aName)
{
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetParentObject());
nsCOMPtr<nsIGlobalObject> global = GetParentObject();
if (!global) {
NS_WARNING("Passed non-global to MediaKeys ctor!");
aRv.Throw(NS_ERROR_UNEXPECTED);
Expand Down
6 changes: 2 additions & 4 deletions dom/payments/PaymentRequestService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ PaymentRequestEnumerator::GetNext(nsISupports** aItem)
if (!rowRequest) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsIPaymentRequest> request = do_QueryInterface(rowRequest);
mIndex++;
request.forget(aItem);
rowRequest.forget(aItem);
return NS_OK;
}

Expand Down Expand Up @@ -114,8 +113,7 @@ PaymentRequestService::GetPaymentRequestById(const nsAString& aRequestId,
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIPaymentRequest> request = do_QueryInterface(rowRequest);
request.forget(aRequest);
rowRequest.forget(aRequest);
return NS_OK;
}

Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/base/nsPluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1866,7 +1866,7 @@ nsPluginHost::SiteHasData(nsIPluginTag* plugin, const nsACString& domain,

// Get the list of sites from the plugin
nsCOMPtr<GetSitesClosure> closure(new GetSitesClosure(domain, this));
rv = library->NPP_GetSitesWithData(nsCOMPtr<nsIGetSitesWithDataCallback>(do_QueryInterface(closure)));
rv = library->NPP_GetSitesWithData(nsCOMPtr<nsIGetSitesWithDataCallback>(closure));
NS_ENSURE_SUCCESS(rv, rv);
// Spin the event loop while we wait for the async call to GetSitesWithData
SpinEventLoopUntil([&]() { return !closure->keepWaiting; });
Expand Down
2 changes: 1 addition & 1 deletion dom/plugins/base/nsPluginInstanceOwner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,

rv = sis->SetData((char *)aHeadersData, aHeadersDataLen);
NS_ENSURE_SUCCESS(rv, rv);
headersDataStream = do_QueryInterface(sis);
headersDataStream = sis;
}

int32_t blockPopups =
Expand Down
3 changes: 1 addition & 2 deletions dom/security/FramingChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ FramingChecker::CheckOneFrameOptionsPolicy(nsIHttpChannel* aHttpChannel,
// principal and use it for the principal comparison. Finding the top
// content-type docshell doesn't work because some chrome documents are
// loaded in content docshells (see bug 593387).
nsCOMPtr<nsIDocShellTreeItem> thisDocShellItem(
do_QueryInterface(static_cast<nsIDocShell*>(aDocShell)));
nsCOMPtr<nsIDocShellTreeItem> thisDocShellItem(aDocShell);
nsCOMPtr<nsIDocShellTreeItem> parentDocShellItem;
nsCOMPtr<nsIDocShellTreeItem> curDocShellItem = thisDocShellItem;
nsCOMPtr<nsIDocument> topDoc;
Expand Down
3 changes: 1 addition & 2 deletions dom/security/SRICheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,7 @@ SRICheckDataVerifier::Verify(const SRIMetadata& aMetadata,

if (MOZ_LOG_TEST(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug)) {
nsAutoCString requestURL;
nsCOMPtr<nsIRequest> request;
request = do_QueryInterface(aChannel);
nsCOMPtr<nsIRequest> request = aChannel;
request->GetName(requestURL);
SRILOG(("SRICheckDataVerifier::Verify, url=%s (length=%zu)",
requestURL.get(), mBytesHashed));
Expand Down
2 changes: 1 addition & 1 deletion dom/serviceworkers/ServiceWorkerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,7 +2029,7 @@ ServiceWorkerPrivate::GetDebugger(nsIWorkerDebugger** aResult)

MOZ_ASSERT(mWorkerPrivate);

nsCOMPtr<nsIWorkerDebugger> debugger = do_QueryInterface(mWorkerPrivate->Debugger());
nsCOMPtr<nsIWorkerDebugger> debugger = mWorkerPrivate->Debugger();
debugger.forget(aResult);

return NS_OK;
Expand Down
Loading

0 comments on commit 837f0af

Please sign in to comment.