Bug 1442453 - Fix nits and get rid of needless QIs. r=baku

This removes some hard tabs that crept in and combines two if branches into a
single statement in order to avoid a bit of duplication.

The existing code here seems to treat any sort of upcast as needing a QI. That
is needlessly wasteful and causes a bunch of unneeded virtual calls.

MozReview-Commit-ID: 7WshYm9C4Xb

--HG--
extra : rebase_source : bc7b1b5157324158f627efd8dff54f078488f4fc
This commit is contained in:
Blake Kaplan 2018-05-30 14:13:07 -07:00
Родитель 5251fffd6b
Коммит 40ee64ba85
7 изменённых файлов: 22 добавлений и 39 удалений

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

@ -79,7 +79,7 @@ PaymentCreateActionRequest::InitRequest(const nsAString& aRequestId,
nsIArray* aMethodData,
nsIPaymentDetails* aDetails,
nsIPaymentOptions* aOptions,
const nsAString& aShippingOption)
const nsAString& aShippingOption)
{
NS_ENSURE_ARG_POINTER(aCallback);
NS_ENSURE_ARG_POINTER(aTopLevelPrincipal);
@ -213,7 +213,7 @@ NS_IMETHODIMP
PaymentUpdateActionRequest::InitRequest(const nsAString& aRequestId,
nsIPaymentActionCallback* aCallback,
nsIPaymentDetails* aDetails,
const nsAString& aShippingOption)
const nsAString& aShippingOption)
{
NS_ENSURE_ARG_POINTER(aCallback);
NS_ENSURE_ARG_POINTER(aDetails);

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

@ -650,7 +650,7 @@ PaymentRequest::CanMakePayment(ErrorResult& aRv)
return nullptr;
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
ErrorResult result;
RefPtr<Promise> promise = Promise::Create(global, result);
if (result.Failed()) {
@ -694,7 +694,7 @@ PaymentRequest::Show(const Optional<OwningNonNull<Promise>>& aDetailsPromise,
return nullptr;
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
ErrorResult result;
RefPtr<Promise> promise = Promise::Create(global, result);
if (result.Failed()) {
@ -794,7 +794,7 @@ PaymentRequest::Abort(ErrorResult& aRv)
return nullptr;
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(GetOwner());
nsCOMPtr<nsIGlobalObject> global = GetOwnerGlobal();
ErrorResult result;
RefPtr<Promise> promise = Promise::Create(global, result);
if (result.Failed()) {

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

@ -634,7 +634,7 @@ PaymentRequest::PaymentRequest(const uint64_t aTabId,
nsIArray* aPaymentMethods,
nsIPaymentDetails* aPaymentDetails,
nsIPaymentOptions* aPaymentOptions,
const nsAString& aShippingOption)
const nsAString& aShippingOption)
: mTabId(aTabId)
, mRequestId(aRequestId)
, mTopLevelPrincipal(aTopLevelPrincipal)

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

@ -458,7 +458,7 @@ PaymentRequestManager::CreatePayment(JSContext* aCx,
methodData,
details,
options,
shippingOption);
shippingOption);
rv = SendRequestPayment(request, action, true);
if (NS_WARN_IF(NS_FAILED(rv))) {

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

@ -57,12 +57,8 @@ PaymentRequestEnumerator::GetNext(nsISupports** aItem)
if (NS_WARN_IF(!request)) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISupports> item = do_QueryInterface(request);
if (NS_WARN_IF(!item)) {
return NS_ERROR_FAILURE;
}
mIndex++;
item.forget(aItem);
request.forget(aItem);
return NS_OK;
}
@ -270,17 +266,13 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest)
nsCOMPtr<nsIPaymentCanMakeActionResponse> canMakeResponse =
do_CreateInstance(NS_PAYMENT_CANMAKE_ACTION_RESPONSE_CONTRACT_ID);
MOZ_ASSERT(canMakeResponse);
if (CanMakePayment(requestId)) {
rv = canMakeResponse->Init(requestId, true);
} else {
rv = canMakeResponse->Init(requestId, false);
}
rv = canMakeResponse->Init(requestId, CanMakePayment(requestId));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIPaymentActionResponse> response = do_QueryInterface(canMakeResponse);
MOZ_ASSERT(response);
rv = RespondPayment(response);
rv = RespondPayment(canMakeResponse.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
@ -304,9 +296,7 @@ PaymentRequestService::RequestPayment(nsIPaymentActionRequest* aRequest)
EmptyString(),
EmptyString(),
EmptyString());
nsCOMPtr<nsIPaymentActionResponse> response = do_QueryInterface(showResponse);
MOZ_ASSERT(response);
rv = RespondPayment(response);
rv = RespondPayment(showResponse.get());
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}

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

@ -136,7 +136,7 @@ PaymentResponse::Complete(PaymentComplete result, ErrorResult& aRv)
return nullptr;
}
nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mOwner);
nsIGlobalObject* global = mOwner->AsGlobal();
ErrorResult errResult;
RefPtr<Promise> promise = Promise::Create(global, errResult);
if (errResult.Failed()) {

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

@ -32,8 +32,6 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest
return IPC_FAIL_NO_REASON(this);
}
nsCOMPtr<nsIPaymentActionRequest> action;
nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
MOZ_ASSERT(callback);
nsresult rv;
switch (aRequest.type()) {
case IPCPaymentActionRequest::TIPCPaymentCreateActionRequest: {
@ -71,13 +69,13 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest
return IPC_FAIL_NO_REASON(this);
}
rv = createAction->InitRequest(request.requestId(),
callback,
this,
mTabId,
request.topLevelPrincipal(),
methodData,
details,
options,
request.shippingOption());
request.shippingOption());
if (NS_WARN_IF(NS_FAILED(rv))) {
return IPC_FAIL_NO_REASON(this);
}
@ -121,7 +119,7 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest
nsCOMPtr<nsIPaymentCompleteActionRequest> completeAction =
do_CreateInstance(NS_PAYMENT_COMPLETE_ACTION_REQUEST_CONTRACT_ID);
rv = completeAction->InitRequest(request.requestId(),
callback,
this,
request.completeStatus());
if (NS_WARN_IF(NS_FAILED(rv))) {
return IPC_FAIL_NO_REASON(this);
@ -142,9 +140,9 @@ PaymentRequestParent::RecvRequestPayment(const IPCPaymentActionRequest& aRequest
nsCOMPtr<nsIPaymentUpdateActionRequest> updateAction =
do_CreateInstance(NS_PAYMENT_UPDATE_ACTION_REQUEST_CONTRACT_ID);
rv = updateAction->InitRequest(request.requestId(),
callback,
this,
details,
request.shippingOption());
request.shippingOption());
action = do_QueryInterface(updateAction);
MOZ_ASSERT(action);
break;
@ -167,8 +165,7 @@ NS_IMETHODIMP
PaymentRequestParent::RespondPayment(nsIPaymentActionResponse* aResponse)
{
if (!NS_IsMainThread()) {
nsCOMPtr<nsIPaymentActionCallback> self = do_QueryInterface(this);
MOZ_ASSERT(self);
nsCOMPtr<nsIPaymentActionCallback> self = this;
nsCOMPtr<nsIPaymentActionResponse> response = aResponse;
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction("PaymentRequestParent::RespondPayment",
[self, response] ()
@ -387,9 +384,7 @@ PaymentRequestParent::ActorDestroy(ActorDestroyReason aWhy)
nsCOMPtr<nsIPaymentRequestService> service =
do_GetService(NS_PAYMENT_REQUEST_SERVICE_CONTRACT_ID);
MOZ_ASSERT(service);
nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
MOZ_ASSERT(callback);
nsresult rv = service->RemoveActionCallback(callback);
nsresult rv = service->RemoveActionCallback(this);
if (NS_WARN_IF(NS_FAILED(rv))) {
MOZ_ASSERT(false);
}
@ -404,9 +399,7 @@ PaymentRequestParent::CreateActionRequest(const nsAString& aRequestId,
nsCOMPtr<nsIPaymentActionRequest> action =
do_CreateInstance(NS_PAYMENT_ACTION_REQUEST_CONTRACT_ID);
MOZ_ASSERT(action);
nsCOMPtr<nsIPaymentActionCallback> callback = do_QueryInterface(this);
MOZ_ASSERT(callback);
nsresult rv = action->Init(aRequestId, aActionType, callback);
nsresult rv = action->Init(aRequestId, aActionType, this);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}