Closed Bug 1142503 Opened 5 years ago Closed 5 years ago

don't use QueryInterface when the compiler can do the cast for us

Categories

(Core :: General, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla39
Tracking Status
firefox39 --- fixed

People

(Reporter: froydnj, Assigned: froydnj)

Details

Attachments

(1 file)

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.
Comment on attachment 8576654 [details] [diff] [review]
don't use QueryInterface when the compiler can do the cast for us

Review of attachment 8576654 [details] [diff] [review]:
-----------------------------------------------------------------

Nice!  How did you find these?

::: editor/txtsvc/nsTextServicesDocument.cpp
@@ +2000,5 @@
>  
>      NS_ENSURE_TRUE(bodyElement, NS_ERROR_FAILURE);
>  
> +    bodyElement.forget(aNode);
> +    result = NS_OK;

result is already successful, not sure if you need to reset it here.

@@ +2015,5 @@
>  
>      NS_ENSURE_TRUE(docElement, NS_ERROR_FAILURE);
>  
> +    docElement.forget(aNode);
> +    result = NS_OK;

Ditto.

::: embedding/components/commandhandler/nsCommandGroup.cpp
@@ +292,1 @@
>    if (!groupsEnum) return NS_ERROR_OUT_OF_MEMORY;

Please remove this check while you're here.

@@ +306,1 @@
>    if (!theGroupEnum) return NS_ERROR_OUT_OF_MEMORY;

This too.
Attachment #8576654 - Flags: review?(ehsan) → review+
(In reply to :Ehsan Akhgari (not reading bugmail, needinfo? me!) from comment #2)
> Nice!  How did you find these?

grep '->QueryInterface(NS_GET_IID'

I confess to not fixing the ones in rdf/ or in various test files.
https://hg.mozilla.org/mozilla-central/rev/27533222749d
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.