Closed
Bug 1289137
Opened 8 years ago
Closed 8 years ago
Make XPCNativeSet::NewInstance() take an nsTArray argument
Categories
(Core :: XPConnect, defect)
Core
XPConnect
Tracking
()
RESOLVED
FIXED
mozilla51
People
(Reporter: mccr8, Assigned: mccr8)
References
Details
Attachments
(1 file, 2 obsolete files)
Right now, it takes an XPCNativeInterface** argument which requires manual cleanup in the caller, and is ugly to iterate over.
Assignee | ||
Comment 1•8 years ago
|
||
This code is mostly untouched since the initial XPCDOM landing in 2001.
Assignee | ||
Comment 2•8 years ago
|
||
ASan try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=9008017e28f2
Assignee | ||
Comment 3•8 years ago
|
||
I could clean up ArrayAutoMarkingPtr more, but it is going to be removed entirely in bug 1288870.
Assignee | ||
Comment 4•8 years ago
|
||
Bobby, are you okay with billm reviewing this? I think the only tricky non-generic part is understanding ArrayAutoMarkingPtr and Bill is probably most familiar with it.
Flags: needinfo?(bobbyholley)
Assignee | ||
Comment 5•8 years ago
|
||
I suppose this request is redundant with my one in bug 1288817, so I'll just clear it and ask Bill for review. Feel free to register an objection. :)
Flags: needinfo?(bobbyholley)
Comment 6•8 years ago
|
||
Comment on attachment 8774380 [details] [diff] [review] Make XPCNativeSet::NewInstance() take an nsTArray argument. Review of attachment 8774380 [details] [diff] [review]: ----------------------------------------------------------------- Setting r?
Attachment #8774380 -
Flags: review?(wmccloskey)
Assignee | ||
Comment 7•8 years ago
|
||
Oops, thanks.
Assignee | ||
Updated•8 years ago
|
Attachment #8774380 -
Attachment is obsolete: true
Attachment #8774380 -
Flags: review?(wmccloskey)
Assignee | ||
Comment 9•8 years ago
|
||
I could clean up ArrayAutoMarkingPtr more, but it is going to be removed entirely in bug 1288870. Review commit: https://reviewboard.mozilla.org/r/69788/diff/#index_header See other reviews: https://reviewboard.mozilla.org/r/69788/
Attachment #8778485 -
Flags: review?(wmccloskey)
Assignee | ||
Updated•8 years ago
|
Attachment #8776169 -
Attachment is obsolete: true
Attachment #8776169 -
Flags: review?(wmccloskey)
Comment 10•8 years ago
|
||
mozreview-review |
Comment on attachment 8778485 [details] Bug 1289137 - Make XPCNativeSet::NewInstance() take an nsTArray argument. https://reviewboard.mozilla.org/r/69788/#review67442 ::: js/xpconnect/src/XPCWrappedNativeInfo.cpp:490 (Diff revision 1) > - // hacky way to get a XPCNativeInterface** using the AutoPtr > - XPCNativeInterface* temp[] = {iface}; > - set = NewInstance(temp, 1); > + AutoTArray<XPCNativeInterface*, 1> temp; > + temp.AppendElement(iface); > + set = NewInstance(temp); I would recommed passing the nsTArray to NewInstance as an nsTArray&&. Then you could call: set = NewInstance(AutoTArray<XPCNI*, 1>(iface)); I think this should work and be efficient. ::: js/xpconnect/src/XPCWrappedNativeInfo.cpp:567 (Diff revision 1) > - *(currentInterface++) = iface; > + interfaceArray.AppendElement(iface); > - interfaceCount++; > } > > - if (interfaceCount) { > - set = NewInstance(interfaceArray, interfaceCount); > + if (interfaceArray.Length() > 0) { > + set = NewInstance(interfaceArray); You would need to use Move here if you take my suggestion. ::: js/xpconnect/src/XPCWrappedNativeInfo.cpp:641 (Diff revision 1) > - set = NewInstance(&newInterface, 1); > + AutoTArray<XPCNativeInterface*, 1> temp; > + temp.AppendElement(newInterface); > + set = NewInstance(temp); Can use the same pattern here as above.
Attachment #8778485 -
Flags: review?(wmccloskey) → review+
Assignee | ||
Comment 11•8 years ago
|
||
(In reply to Bill McCloskey (:billm) from comment #10) > I would recommed passing the nsTArray to NewInstance as an nsTArray&&. That's pretty nice. Unfortunately, that doesn't work, because you can't pass in a single argument to the ctor. I'd noticed that before, which is why there was the AppendElement() on a second line. It looks like AutoTArray is just missing a ctor with initializer_list like the other array types, so I'll file a bug for that and then make the changes you suggest, assuming there are no issues there.
Oops. I read over that code and thought I saw it. The initializer_list thing sounds good.
Assignee | ||
Comment 13•8 years ago
|
||
Thinking about this some more, I might as well just use nsTArray in the caller: moving from an AutoTArray to an nsTArray is surely going to cause a heap allocation, so I might as well not bother with the auto array. This is technically less efficient, but I'm sure it doesn't matter. And I can just do this, which is slick: set = NewInstance({newInterface});
Comment hidden (mozreview-request) |
Comment 15•8 years ago
|
||
Pushed by amccreight@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a7a5fd1b36e5 Make XPCNativeSet::NewInstance() take an nsTArray argument. r=billm
(In reply to Andrew McCreight [:mccr8] from comment #13) > Thinking about this some more, I might as well just use nsTArray in the > caller: moving from an AutoTArray to an nsTArray is surely going to cause a > heap allocation, so I might as well not bother with the auto array. This is > technically less efficient, but I'm sure it doesn't matter. > > And I can just do this, which is slick: > set = NewInstance({newInterface}); We're not actually moving (as in invoking a move constructor), we're just passing a reference. So I think it would have stayed an AutoTArray the whole time. But yeah, it doesn't really matter.
Comment 17•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/a7a5fd1b36e5
Status: NEW → RESOLVED
Closed: 8 years ago
status-firefox51:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
You need to log in
before you can comment on or make changes to this bug.
Description
•