forked from boostorg/beast
Test self copy, self move for dynamic buffers:
* Swap * Copy assignment to self * Move assignment to self
This commit is contained in:
1 parent
05d22802ec
commit
74293fb8a5
7 files changed
+71
-32
No files matched your search
@@ -246,7 +246,7 @@ protected:
|
||||
private:
|
||||
static
|
||||
std::size_t
|
||||
dist(char const* first, char const* last)
|
||||
dist(char const* first, char const* last) noexcept
|
||||
{
|
||||
return static_cast<std::size_t>(last - first);
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ class buffers_adaptor<MutableBufferSequence>::
|
||||
readable_bytes<isMutable>::
|
||||
const_iterator
|
||||
{
|
||||
iter_type it_;
|
||||
iter_type it_{};
|
||||
buffers_adaptor const* b_ = nullptr;
|
||||
|
||||
public:
|
||||
@@ -259,7 +259,7 @@ template<class MutableBufferSequence>
|
||||
class buffers_adaptor<MutableBufferSequence>::
|
||||
mutable_buffers_type::const_iterator
|
||||
{
|
||||
iter_type it_;
|
||||
iter_type it_{};
|
||||
buffers_adaptor const* b_ = nullptr;
|
||||
|
||||
public:
|
||||
@@ -442,6 +442,8 @@ buffers_adaptor<MutableBufferSequence>::
|
||||
operator=(buffers_adaptor const& other) ->
|
||||
buffers_adaptor&
|
||||
{
|
||||
if(this == &other)
|
||||
return *this;
|
||||
auto const nbegin = std::distance<iter_type>(
|
||||
net::buffer_sequence_begin(other.bs_),
|
||||
other.begin_);
|
||||
|
||||
@@ -30,9 +30,10 @@ template<class Allocator>
|
||||
basic_flat_buffer<Allocator>::
|
||||
~basic_flat_buffer()
|
||||
{
|
||||
if(begin_)
|
||||
alloc_traits::deallocate(
|
||||
this->get(), begin_, capacity());
|
||||
if(! begin_)
|
||||
return;
|
||||
alloc_traits::deallocate(
|
||||
this->get(), begin_, capacity());
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
@@ -124,24 +125,23 @@ basic_flat_buffer(
|
||||
max_ = other.max_;
|
||||
copy_from(other);
|
||||
other.clear();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
begin_ = other.begin_;
|
||||
in_ = other.in_;
|
||||
out_ = other.out_;
|
||||
last_ = other.out_; // invalidate
|
||||
end_ = other.end_;
|
||||
max_ = other.max_;
|
||||
BOOST_ASSERT(
|
||||
alloc_traits::max_size(this->get()) ==
|
||||
alloc_traits::max_size(other.get()));
|
||||
other.begin_ = nullptr;
|
||||
other.in_ = nullptr;
|
||||
other.out_ = nullptr;
|
||||
other.last_ = nullptr;
|
||||
other.end_ = nullptr;
|
||||
}
|
||||
|
||||
begin_ = other.begin_;
|
||||
in_ = other.in_;
|
||||
out_ = other.out_;
|
||||
last_ = other.out_; // invalidate
|
||||
end_ = other.end_;
|
||||
max_ = other.max_;
|
||||
BOOST_ASSERT(
|
||||
alloc_traits::max_size(this->get()) ==
|
||||
alloc_traits::max_size(other.get()));
|
||||
other.begin_ = nullptr;
|
||||
other.in_ = nullptr;
|
||||
other.out_ = nullptr;
|
||||
other.last_ = nullptr;
|
||||
other.end_ = nullptr;
|
||||
}
|
||||
|
||||
template<class Allocator>
|
||||
@@ -217,8 +217,9 @@ basic_flat_buffer<Allocator>::
|
||||
operator=(basic_flat_buffer&& other) noexcept ->
|
||||
basic_flat_buffer&
|
||||
{
|
||||
if(this != &other)
|
||||
move_assign(other, pocma{});
|
||||
if(this == &other)
|
||||
return *this;
|
||||
move_assign(other, pocma{});
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -228,8 +229,9 @@ basic_flat_buffer<Allocator>::
|
||||
operator=(basic_flat_buffer const& other) ->
|
||||
basic_flat_buffer&
|
||||
{
|
||||
if(this != &other)
|
||||
copy_assign(other, pocca{});
|
||||
if(this == &other)
|
||||
return *this;
|
||||
copy_assign(other, pocca{});
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,6 +102,8 @@ operator=(flat_static_buffer const& other) ->
|
||||
flat_static_buffer<N>&
|
||||
{
|
||||
using net::buffer_copy;
|
||||
if(this == &other)
|
||||
return *this;
|
||||
this->consume(this->size());
|
||||
this->commit(buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
|
||||
@@ -145,6 +145,8 @@ static_buffer<N>::
|
||||
operator=(static_buffer const& other) noexcept ->
|
||||
static_buffer<N>&
|
||||
{
|
||||
if(this == &other)
|
||||
return *this;
|
||||
this->consume(this->size());
|
||||
this->commit(net::buffer_copy(
|
||||
this->prepare(other.size()), other.data()));
|
||||
|
||||
Reference in new issue
Block a user