util/ForeignFifoBuffer: add MoveFrom() overload with std::span
This commit is contained in:
parent
93bf0fc547
commit
70808bde64
@ -222,11 +222,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the number of items moved
|
* @return the number of items moved
|
||||||
*/
|
*/
|
||||||
constexpr size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept {
|
template<typename U>
|
||||||
auto r = src.Read();
|
constexpr size_type MoveFrom(std::span<U> src) noexcept {
|
||||||
auto w = Write();
|
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
|
/* if the source contains more data than we
|
||||||
can append at the tail, try to make more
|
can append at the tail, try to make more
|
||||||
room by shifting the head to 0 */
|
room by shifting the head to 0 */
|
||||||
@ -234,13 +234,18 @@ public:
|
|||||||
w = Write();
|
w = Write();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r.size() > w.size())
|
if (src.size() > w.size())
|
||||||
r = r.first(w.size());
|
src = src.first(w.size());
|
||||||
|
|
||||||
std::move(r.begin(), r.end(), w.begin());
|
std::move(src.begin(), src.end(), w.begin());
|
||||||
Append(r.size());
|
Append(src.size());
|
||||||
src.Consume(r.size());
|
return src.size();
|
||||||
return r.size();
|
}
|
||||||
|
|
||||||
|
constexpr size_type MoveFrom(ForeignFifoBuffer<T> &src) noexcept {
|
||||||
|
auto n = MoveFrom(src.Read());
|
||||||
|
src.Consume(n);
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user