Avoid copies in handler_alloc

This commit is contained in:
Vinnie Falco
2017-01-05 09:09:59 -05:00
parent 4ab2b5e5e7
commit ffe2e8e02b
2 changed files with 9 additions and 24 deletions

View File

@ -3,6 +3,7 @@
* Fix broken Intellisense * Fix broken Intellisense
* Implement the Asio deallocation-before-invocation guarantee * Implement the Asio deallocation-before-invocation guarantee
* Add handler helpers * Add handler helpers
* Avoid copies in handler_alloc
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -28,11 +28,10 @@ namespace beast {
@tparam T The type of objects allocated by the allocator. @tparam T The type of objects allocated by the allocator.
@tparam CompletionHandler The type of handler. Copies will be made @tparam CompletionHandler The type of handler.
of the handler as needed.
@note Allocated memory is only valid until the handler is called. The @note Memory allocated by this allocator must be freed before
caller is still responsible for freeing memory. the handler is invoked or undefined behavior results.
*/ */
#if GENERATING_DOCS #if GENERATING_DOCS
template<class T, class CompletionHandler> template<class T, class CompletionHandler>
@ -50,7 +49,7 @@ private:
template<class U, class H> template<class U, class H>
friend class handler_alloc; friend class handler_alloc;
CompletionHandler h_; CompletionHandler& h_;
public: public:
using value_type = T; using value_type = T;
@ -70,31 +69,16 @@ public:
/** Construct the allocator. /** Construct the allocator.
The handler is moved or copied into the allocator. A reference of the handler is stored. The handler must
remain valid for at least the lifetime of the allocator.
*/ */
explicit explicit
handler_alloc(CompletionHandler&& h) handler_alloc(CompletionHandler& h)
: h_(std::move(h))
{
}
/** Construct the allocator.
A copy of the handler is made.
*/
explicit
handler_alloc(CompletionHandler const& h)
: h_(h) : h_(h)
{ {
} }
template<class U> /// Copy constructor
handler_alloc(
handler_alloc<U, CompletionHandler>&& other)
: h_(std::move(other.h_))
{
}
template<class U> template<class U>
handler_alloc( handler_alloc(
handler_alloc<U, CompletionHandler> const& other) handler_alloc<U, CompletionHandler> const& other)