Closed Bug 1500811 Opened 6 years ago Closed 4 years ago

Maybe and Variant should provide rvalue-qualified accessors

Categories

(Core :: MFBT, enhancement)

enhancement
Not set
normal

Tracking

()

RESOLVED FIXED
85 Branch
Tracking Status
firefox64 --- wontfix
firefox85 --- fixed

People

(Reporter: mozbugz, Assigned: mozbugz)

References

(Blocks 2 open bugs)

Details

Attachments

(2 files)

Currently Maybe::operator*(), Variant::as<U>(), and other similar accessors don't have different implementations for rvalue-qualified `this` objects, which means that if the Maybe object is an rvalue (e.g., returned from a function, or explicitly move()'d), its contained object is not efficiently moved when possible. As a quick exercise, I tried `Maybe::operator*() && = delete;` to check if we had such cases, and the build quickly failed with a few errors. I did not examine the code further, maybe all these objects are small&simple enough that copying is just as good as moving? But it at least shows that this situation exists. And from what I've read, the `const &&` option should be implemented as well, as it could happen in some situations. Note that it is provided in std::optional: https://en.cppreference.com/w/cpp/utility/optional/operator*
The cppreference link above doesn't work (Bugzilla doesn't include the final '*' -- I've opened bug 1500883 to see if it should&could be fixed). In the meantime this one should work: https://en.cppreference.com/w/cpp/utility/optional/operator%2A

There are also equivalents for const&&, which should be rare.

The change in SavedStacks.cpp was necessary because cache->insert takes an lvalue-ref, but *lookup.framePtr() now returns an rvalue-ref (as it should).

Assignee: nobody → gsquelart
Status: NEW → ASSIGNED

as<...>() on an rvalue variant returns the contained value as rvalue-reference.
match() on an rvalue variant forwards the contained value as rvalue-reference.
So now the contained values can be efficiently moved-from.

There are also equivalents for const&&, which should be rare.

Depends on D98049

Pushed by gsquelart@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/a8f88652ea6d Maybe::operator*()&&, ref()&&, value()&& - r=sg,sfink https://hg.mozilla.org/integration/autoland/rev/273d6825ba47 Variant::as()&&, match()&& - r=sg
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 85 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: