Closed Bug 1289457 Opened 4 years ago Closed 4 years ago

Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate}

Categories

(Core :: XPConnect, defect)

defect
Not set

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox50 --- fixed

People

(Reporter: mccr8, Assigned: mccr8)

References

Details

Attachments

(1 file)

XPCNativeSet::NewInstance and XPCNativeSet::NewInstanceMutate each null check the results of two different calls to new, which is unnecessary because new is infallible.
Comment on attachment 8775375 [details]
Bug 1289457 - Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate} to skip checks.

https://reviewboard.mozilla.org/r/67544/#review64684

::: js/xpconnect/src/XPCWrappedNativeInfo.cpp
(Diff revision 1)
>          size += (slots - 1) * sizeof(XPCNativeInterface*);
>      void* place = new char[size];
> -    if (place)
> +    XPCNativeSet* obj = new(place) XPCNativeSet();
> -        obj = new(place) XPCNativeSet();
>  
> -    if (obj) {

Wow, this was some ugly code!

Thanks for cleaning it up.
Attachment #8775375 - Flags: review?(mrbkap) → review+
Pushed by amccreight@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/5f0c9095c0ff
Take advantage of infallible new in XPCNativeSet::NewInstance{,Mutate} to skip checks. r=mrbkap
https://hg.mozilla.org/mozilla-central/rev/5f0c9095c0ff
Status: NEW → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
You need to log in before you can comment on or make changes to this bug.