add folly::Function::asSharedProxy
Summary:
This diff adds a method to folly::Function that moves the
Function object into a copyable, callable proxy object.
folly::Function already has the asStdFunction method, which
does the same, but wraps the proxy object in a std::function.
When a copyable shared-state proxy of a folly::Function is needed,
it is not necessarily to turn it into a std::function.
If instead the shared proxy will be passed to several functions
taking folly::Function, what happens is the folly::Function
is moved on the heap, a shared_ptr is put into a std::function,
and that is wrapped in a new folly::Function, which always
requires a memory allocation, because std::function is not
noexcept-movable. When using asSharedProxy instead, an
unspecified copyable type is returned that can implicitly
converted into a folly::Function, but without an additional
memory allocation at this point.
Reviewed By: yfeldblum
Differential Revision:
D4048621
fbshipit-source-id:
b642027b0a6957058fe0089cceeb657ec52e8669