From cd241a93c1688a2677cd0e17a9c424960c79431a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 11 Jul 2022 22:28:31 +0200 Subject: [PATCH] util/DynamicFifoBuffer: pass std::span to Append() --- src/encoder/plugins/FlacEncoderPlugin.cxx | 2 +- src/encoder/plugins/NullEncoderPlugin.cxx | 2 +- src/encoder/plugins/ShineEncoderPlugin.cxx | 4 ++-- src/util/DynamicFifoBuffer.hxx | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/encoder/plugins/FlacEncoderPlugin.cxx b/src/encoder/plugins/FlacEncoderPlugin.cxx index d40a05295..be97648a5 100644 --- a/src/encoder/plugins/FlacEncoderPlugin.cxx +++ b/src/encoder/plugins/FlacEncoderPlugin.cxx @@ -85,7 +85,7 @@ private: [[maybe_unused]] unsigned current_frame, void *client_data) noexcept { auto &encoder = *(FlacEncoder *)client_data; - encoder.output_buffer.Append((const std::byte *)data, bytes); + encoder.output_buffer.Append({(const std::byte *)data, bytes}); return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; } }; diff --git a/src/encoder/plugins/NullEncoderPlugin.cxx b/src/encoder/plugins/NullEncoderPlugin.cxx index dd44fe276..f34cc1ea3 100644 --- a/src/encoder/plugins/NullEncoderPlugin.cxx +++ b/src/encoder/plugins/NullEncoderPlugin.cxx @@ -30,7 +30,7 @@ public: /* virtual methods from class Encoder */ void Write(const void *data, size_t length) override { - buffer.Append((const std::byte *)data, length); + buffer.Append({(const std::byte *)data, length}); } size_t Read(void *dest, size_t length) override { diff --git a/src/encoder/plugins/ShineEncoderPlugin.cxx b/src/encoder/plugins/ShineEncoderPlugin.cxx index b7072238b..19a4cd776 100644 --- a/src/encoder/plugins/ShineEncoderPlugin.cxx +++ b/src/encoder/plugins/ShineEncoderPlugin.cxx @@ -156,7 +156,7 @@ ShineEncoder::WriteChunk(bool flush) shine_encode_buffer(shine, stereo, &written); if (written > 0) - output_buffer.Append(out, written); + output_buffer.Append({out, std::size_t(written)}); input_pos = 0; } @@ -199,7 +199,7 @@ ShineEncoder::Flush() const auto data = (const std::byte *)shine_flush(shine, &written); if (written > 0) - output_buffer.Append(data, written); + output_buffer.Append({data, std::size_t(written)}); } const EncoderPlugin shine_encoder_plugin = { diff --git a/src/util/DynamicFifoBuffer.hxx b/src/util/DynamicFifoBuffer.hxx index 6fa529574..a4cc2f5c2 100644 --- a/src/util/DynamicFifoBuffer.hxx +++ b/src/util/DynamicFifoBuffer.hxx @@ -109,9 +109,9 @@ public: /** * Append data to the buffer, growing it as needed. */ - void Append(const_pointer p, size_type n) noexcept { - std::copy_n(p, n, Write(n)); - Append(n); + void Append(std::span src) noexcept { + std::copy(src.begin(), src.end(), Write(src.size())); + Append(src.size()); } protected: