From 2beb763b4f3d12de7240d9811d8e4baaa094aab6 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 7 Aug 2014 08:53:02 +0200 Subject: [PATCH] util/ForeignFifoBuffer: add method MoveFrom() --- src/util/ForeignFifoBuffer.hxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util/ForeignFifoBuffer.hxx b/src/util/ForeignFifoBuffer.hxx index cd6fb6101..c52846727 100644 --- a/src/util/ForeignFifoBuffer.hxx +++ b/src/util/ForeignFifoBuffer.hxx @@ -204,6 +204,22 @@ public: return n; } + /** + * Move as much data as possible from the specified buffer. + * + * @return the number of items moved + */ + size_type MoveFrom(ForeignFifoBuffer &src) { + auto r = src.Read(); + auto w = Write(); + size_t n = std::min(r.size, w.size); + + std::move(r.data, r.data + n, w.data); + Append(n); + src.Consume(n); + return n; + } + protected: void Shift() { if (head == 0)