Closed
Bug 1254565
Opened 8 years ago
Closed 8 years ago
Support passing rvalue matchers into mozilla::Variant::match
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
FIXED
mozilla48
Tracking | Status | |
---|---|---|
firefox48 | --- | fixed |
People
(Reporter: fitzgen, Assigned: fitzgen)
References
Details
Attachments
(1 file, 2 obsolete files)
4.09 KB,
patch
|
fitzgen
:
review+
|
Details | Diff | Splinter Review |
We have two versions right now: one for `const Matcher&` and one for `Matcher&` and I think we can combine them into one version. Additionally, if we make it `Matcher&&`, the existing cases already work because Matcher is a template type parameter so it works similar to perfect forwarding except we aren't doing any constructing, and we can also do v.match(SomeMatcher()); instead of SomeMatcher m; v.match(m); which we have to do now and is pretty annoying.
Assignee | ||
Comment 1•8 years ago
|
||
So `Matcher&& aMatcher` didn't work but `Matcher aMatcher` does. Will this prefer passing by reference and avoiding copies when either could happen?
Attachment #8728183 -
Flags: review?(nfroyd)
Assignee | ||
Comment 2•8 years ago
|
||
Try push: https://treeherder.mozilla.org/#/jobs?repo=try&revision=e3e92af0f17d
Assignee | ||
Updated•8 years ago
|
Summary: Clean up mozilla::Variant::match → Support passing rvalue matchers into mozilla::Variant::match
Comment 3•8 years ago
|
||
(In reply to Nick Fitzgerald [:fitzgen] [⏰PST; UTC-8] from comment #1) > So `Matcher&& aMatcher` didn't work How didn't it work? Doesn't perfect forwarding kick in in this case?
Assignee | ||
Comment 4•8 years ago
|
||
(In reply to JW Wang [:jwwang] from comment #3) > (In reply to Nick Fitzgerald [:fitzgen] [⏰PST; UTC-8] from comment #1) > > So `Matcher&& aMatcher` didn't work > How didn't it work? Doesn't perfect forwarding kick in in this case? That was what I had thought/hoped would happen, but the compiler did not agree. I don't remember the specific message anymore, but you could certainly try it locally.
Comment 5•8 years ago
|
||
template<typename Matcher, typename ConcreteVariant, typename ReturnType = typename RemoveReference<Matcher>::Type::ReturnType> static ReturnType match(Matcher&& aMatcher, ConcreteVariant& aV) { return aMatcher.match(aV.template as<T>()); } RemoveReference needs to be applied to Matcher so ReturnType can be deducted correctly.
Assignee | ||
Comment 6•8 years ago
|
||
Awesome, thanks! I will attach a new patch in a bit :)
Comment 7•8 years ago
|
||
Comment on attachment 8728183 [details] [diff] [review] Allow passing matchers as rvalues to Variant::match Review of attachment 8728183 [details] [diff] [review]: ----------------------------------------------------------------- Sounds like Nick's going to put up a new patch, so I'm going to get this one out of my queue. :)
Attachment #8728183 -
Flags: review?(nfroyd)
Assignee | ||
Comment 8•8 years ago
|
||
Attachment #8728517 -
Flags: review?(nfroyd)
Assignee | ||
Updated•8 years ago
|
Attachment #8728183 -
Attachment is obsolete: true
Assignee | ||
Comment 9•8 years ago
|
||
New try push: https://treeherder.mozilla.org/#/jobs?repo=try&revision=8c5999003024
Comment 10•8 years ago
|
||
Comment on attachment 8728517 [details] [diff] [review] Allow passing matchers as rvalues to Variant::match Review of attachment 8728517 [details] [diff] [review]: ----------------------------------------------------------------- I am a bit surprised this takes so little code. r=me, but I am interested to hear your thoughts on the suggestions below. ::: mfbt/Variant.h @@ +553,5 @@ > MOZ_ASSERT(is<T>()); > return T(Move(as<T>())); > } > > + // Exhaustive matching of all variant types on the contained value. What, no separate patch for this?? ;) @@ +558,5 @@ > > /** Match on an immutable const reference. */ > + template<typename Matcher, > + typename ReturnType = typename RemoveReference<Matcher>::Type::ReturnType> > + ReturnType I do like naming things better, but I wonder if we'd be better off not exposing this as an actual template parameter, but just sucking it up and saying: template<typename Matcher> typename RemoveReference<Matcher>::Type::ReturnType match(Matcher&& aMatcher) so as to not potentially imply to people that they could provide their own ReturnType, were they so inclined to be clever. I'm less concerned about the usages in VariantImplementation, as those are internal details. Also not sure if it's worth defining a separate helper template structure so as to not be saying RemoveReference<Matcher>::Type::ReturnType everywhere.
Attachment #8728517 -
Flags: review?(nfroyd) → review+
Assignee | ||
Comment 11•8 years ago
|
||
Removed the type parameter for the public, non-detail changes and inlined the whole expression instead. Good call. Carrying r+.
Attachment #8729191 -
Flags: review+
Assignee | ||
Updated•8 years ago
|
Attachment #8728517 -
Attachment is obsolete: true
Assignee | ||
Comment 12•8 years ago
|
||
New try push: https://treeherder.mozilla.org/#/jobs?repo=try&revision=5c0f328a3f4e
Assignee | ||
Updated•8 years ago
|
Keywords: checkin-needed
Comment 13•8 years ago
|
||
https://hg.mozilla.org/integration/mozilla-inbound/rev/4dccba6aa5a2
Keywords: checkin-needed
Comment 14•8 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/4dccba6aa5a2
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
status-firefox48:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla48
You need to log in
before you can comment on or make changes to this bug.
Description
•