aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-08-07 08:53:02 +0200
committerMax Kellermann <max@duempel.org>2014-08-07 08:53:02 +0200
commit2beb763b4f3d12de7240d9811d8e4baaa094aab6 (patch)
tree946390bdfba6ed65954995d2e6ee16bbc33f8b6d /src/util
parent69ae879c585039297951821e353f7c1ca12b6cb8 (diff)
downloadmpd-2beb763b4f3d12de7240d9811d8e4baaa094aab6.tar.gz
mpd-2beb763b4f3d12de7240d9811d8e4baaa094aab6.tar.xz
mpd-2beb763b4f3d12de7240d9811d8e4baaa094aab6.zip
util/ForeignFifoBuffer: add method MoveFrom()
Diffstat (limited to 'src/util')
-rw-r--r--src/util/ForeignFifoBuffer.hxx16
1 files changed, 16 insertions, 0 deletions
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<T> &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)