parent
97da2adbca
commit
ec54e7f11e
|
@ -263,8 +263,23 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::pair<value_type*, size_t> reserve_space(size_t n_bytes) override
|
virtual std::pair<value_type*, size_t> reserve_space(size_t n_bytes) override
|
||||||
|
{
|
||||||
|
if (auto const free_at_end = buf_.size() - end_pos_; free_at_end < n_bytes)
|
||||||
|
{
|
||||||
|
if (auto const total_free = begin_pos_ + free_at_end; total_free >= n_bytes)
|
||||||
|
{
|
||||||
|
// move data so that all free space is at the end
|
||||||
|
auto const size = this->size();
|
||||||
|
std::copy(data(), data() + size, std::data(buf_));
|
||||||
|
begin_pos_ = 0;
|
||||||
|
end_pos_ = size;
|
||||||
|
}
|
||||||
|
else // even `total_free` is not enough, so resize
|
||||||
{
|
{
|
||||||
buf_.resize(end_pos_ + n_bytes);
|
buf_.resize(end_pos_ + n_bytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return { buf_.data() + end_pos_, n_bytes };
|
return { buf_.data() + end_pos_, n_bytes };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue