summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2018-08-20 15:21:05 +0200
committerMax Kellermann <max@musicpd.org>2018-08-20 15:21:05 +0200
commit36ca9d01fbd9cd996472f4ebcbceb25b955d707c (patch)
treeec089c3fc74bf1bbcca9dd896b5bbb43c93e7bef /src
parent3bceed1b536a396405756fa2d61accbcdf101169 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/util/ForeignFifoBuffer.hxx9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/util/ForeignFifoBuffer.hxx b/src/util/ForeignFifoBuffer.hxx
index da0058ad3..bcc2b9d67 100644
--- a/src/util/ForeignFifoBuffer.hxx
+++ b/src/util/ForeignFifoBuffer.hxx
@@ -223,6 +223,15 @@ public:
size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept {
auto r = src.Read();
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);
std::move(r.data, r.data + n, w.data);