Commit 36ca9d01 authored by Max Kellermann's avatar Max Kellermann

util/ForeignFifoBuffer: shift the buffer in MoveFrom() on demand

The API documentation says "move as much data as possible", and if there is room at the head of the buffer, we should use that if the room after the tail is not large enough.
parent 3bceed1b
...@@ -223,6 +223,15 @@ public: ...@@ -223,6 +223,15 @@ public:
size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept { size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept {
auto r = src.Read(); auto r = src.Read();
auto w = Write(); auto w = Write();
if (w.size < r.size && head > 0) {
/* if the source contains more data than we
can append at the tail, try to make more
room by shifting the head to 0 */
Shift();
w = Write();
}
size_t n = std::min(r.size, w.size); size_t n = std::min(r.size, w.size);
std::move(r.data, r.data + n, w.data); std::move(r.data, r.data + n, w.data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment