Reset internal buffer position on next()

This commit is contained in:
Ivan Lezhankin 2021-02-03 15:31:45 +03:00
parent 3b52b04008
commit b0f400ca1b
2 changed files with 13 additions and 9 deletions

View File

@ -40,6 +40,7 @@ public:
inline Position end() const { return end_pos; }
inline size_t size() const { return size_t(end_pos - begin_pos); }
inline void resize(size_t size) { end_pos = begin_pos + size; }
inline bool empty() const { return size() == 0; }
inline void swap(Buffer & other)
{

View File

@ -25,11 +25,16 @@ protected:
return false;
/// First reading
if (working_buffer.size() == 0 && (*current)->hasPendingData())
if (working_buffer.empty())
{
if ((*current)->hasPendingData())
{
working_buffer = Buffer((*current)->position(), (*current)->buffer().end());
return true;
}
}
else
(*current)->position() = position();
if (!(*current)->next())
{
@ -51,14 +56,12 @@ protected:
}
public:
ConcatReadBuffer(const ReadBuffers & buffers_) : ReadBuffer(nullptr, 0), buffers(buffers_), current(buffers.begin()) {}
ConcatReadBuffer(ReadBuffer & buf1, ReadBuffer & buf2) : ReadBuffer(nullptr, 0)
explicit ConcatReadBuffer(const ReadBuffers & buffers_) : ReadBuffer(nullptr, 0), buffers(buffers_), current(buffers.begin())
{
buffers.push_back(&buf1);
buffers.push_back(&buf2);
current = buffers.begin();
assert(!buffers.empty());
}
ConcatReadBuffer(ReadBuffer & buf1, ReadBuffer & buf2) : ConcatReadBuffer({&buf1, &buf2}) {}
};
}