mirror of
https://github.com/boostorg/beast.git
synced 2025-07-31 05:17:26 +02:00
Avoid copies in handler_alloc
This commit is contained in:
@ -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
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
Reference in New Issue
Block a user