Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created February 14, 2020 20:55
Show Gist options
  • Save vinniefalco/85bd5b30bc426cc1579984beb153c4ce to your computer and use it in GitHub Desktop.
Save vinniefalco/85bd5b30bc426cc1579984beb153c4ce to your computer and use it in GitHub Desktop.
subrange(
basic_multi_buffer const& b,
size_type pos,
size_type n) noexcept
{
pos = pos + b.in_pos_;
auto it = b_->list_.begin();
for(;;)
{
if(it == b_->list_.end())
{
begin_ = it;
end_ = it;
begin_pos_ = 0;
end_pos_ = 0;
return;
}
if(it->size() > pos)
{
begin_ = it;
begin_pos_ = pos;
break;
}
pos -= it->size();
++it;
}
BOOST_ASSERT(
it != b_->list_.end());
auto const last = std::prev(
b_->list_.end());
if(it == last)
{
end_ = it;
if(it == b_>list_.begin())
{
auto const avail =
b_->out_end_ - b_->in_pos_;
if(n >= avail)
end_pos_ = b_->out_end_;
else
end_pos_ = begin_pos_ + n;
}
else
{
auto const avail =
b_->out_end_;
if(n >= avail)
end_pos_ = avail;
else
end_pos_ = n;
}
return;
}
++it;
while(it != last)
{
if(it == b_->list_.end())
{
end_ = it;
end_pos_ = 0;
return;
}
auto size = it->size();
if(n < size)
{
end_ = it;
end_pos_ = n;
return;
}
n -= size;
++it;
}
BOOST_ASSERT(
it != b_->list_.end());
end_ = it;
auto const avail =
b_->out_end_;
if(n >= avail)
end_pos_ = avail;
else
end_pos_ = n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment