0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-26 00:32:35 +01:00

ircd::buffer: Add a data shifter for window_buffer.

This commit is contained in:
Jason Volk 2018-04-10 18:01:20 -07:00
parent 9270937957
commit b1f613b5ac

View file

@ -37,6 +37,7 @@ struct ircd::buffer::window_buffer
const_buffer operator()(const closure &closure);
const_buffer rewind(const size_t &n = 1);
const_buffer shift(const size_t &n);
window_buffer(const mutable_buffer &base);
window_buffer() = default;
@ -48,6 +49,31 @@ ircd::buffer::window_buffer::window_buffer(const mutable_buffer &base)
,base{base}
{}
inline ircd::buffer::const_buffer
ircd::buffer::window_buffer::shift(const size_t &n)
{
const size_t nmax{std::min(n, consumed())};
const const_buffer src
{
base.begin() + nmax, this->begin()
};
const mutable_buffer dst
{
base.begin(), consumed() - nmax
};
assert(size(src) == size(dst));
assert(data(src) >= data(dst));
assert(size(src) <= consumed());
assert(size(dst) <= size(base));
move(dst, src);
rewind(nmax);
assert(base.begin() <= begin());
assert(begin() <= base.end());
return completed();
}
inline ircd::buffer::const_buffer
ircd::buffer::window_buffer::rewind(const size_t &n)
{