From 70808bde64f3cb3be9ad482430ed0ea426549d34 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 30 May 2022 12:54:18 +0200 Subject: [PATCH] util/ForeignFifoBuffer: add MoveFrom() overload with std::span --- src/util/ForeignFifoBuffer.hxx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/util/ForeignFifoBuffer.hxx b/src/util/ForeignFifoBuffer.hxx index e11db2010..c811d9b02 100644 --- a/src/util/ForeignFifoBuffer.hxx +++ b/src/util/ForeignFifoBuffer.hxx @@ -222,11 +222,11 @@ public: * * @return the number of items moved */ - constexpr size_type MoveFrom(ForeignFifoBuffer &src) noexcept { - auto r = src.Read(); + template + constexpr size_type MoveFrom(std::span src) noexcept { auto w = Write(); - if (w.size() < r.size() && head > 0) { + if (src.size() > w.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 */ @@ -234,13 +234,18 @@ public: w = Write(); } - if (r.size() > w.size()) - r = r.first(w.size()); + if (src.size() > w.size()) + src = src.first(w.size()); - std::move(r.begin(), r.end(), w.begin()); - Append(r.size()); - src.Consume(r.size()); - return r.size(); + std::move(src.begin(), src.end(), w.begin()); + Append(src.size()); + return src.size(); + } + + constexpr size_type MoveFrom(ForeignFifoBuffer &src) noexcept { + auto n = MoveFrom(src.Read()); + src.Consume(n); + return n; } protected: