From a79a9fb6921c8ccd7707d0a956e36abb899ed656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Thu, 27 Jan 2022 13:07:06 +0100 Subject: [PATCH] LibAudio: Use ArrayLike concept to remove duplicate Buffer constructor --- Userland/Libraries/LibAudio/Buffer.h | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/Userland/Libraries/LibAudio/Buffer.h b/Userland/Libraries/LibAudio/Buffer.h index 8898634c65..0856d77450 100644 --- a/Userland/Libraries/LibAudio/Buffer.h +++ b/Userland/Libraries/LibAudio/Buffer.h @@ -74,11 +74,8 @@ class Buffer : public RefCounted { public: static ErrorOr> from_pcm_data(ReadonlyBytes data, int num_channels, PcmSampleFormat sample_format); static ErrorOr> from_pcm_stream(InputMemoryStream& stream, int num_channels, PcmSampleFormat sample_format, int num_samples); - static ErrorOr> create_with_samples(Vector&& samples) - { - return adopt_nonnull_ref_or_enomem(new (nothrow) Buffer(move(samples))); - } - static ErrorOr> create_with_samples(FixedArray&& samples) + template ArrayT> + static ErrorOr> create_with_samples(ArrayT&& samples) { return adopt_nonnull_ref_or_enomem(new (nothrow) Buffer(move(samples))); } @@ -100,16 +97,8 @@ public: Core::AnonymousBuffer const& anonymous_buffer() const { return m_buffer; } private: - explicit Buffer(Vector&& samples) - // FIXME: AnonymousBuffers can't be empty, so even for empty buffers we create a buffer of size 1 here, - // although the sample count is set to 0 to mark this. - : m_buffer(Core::AnonymousBuffer::create_with_size(max(samples.size(), 1) * sizeof(Sample)).release_value()) - , m_id(allocate_id()) - , m_sample_count(samples.size()) - { - memcpy(m_buffer.data(), samples.data(), samples.size() * sizeof(Sample)); - } - explicit Buffer(FixedArray&& samples) + template ArrayT> + explicit Buffer(ArrayT&& samples) // FIXME: AnonymousBuffers can't be empty, so even for empty buffers we create a buffer of size 1 here, // although the sample count is set to 0 to mark this. : m_buffer(Core::AnonymousBuffer::create_with_size(max(samples.size(), 1) * sizeof(Sample)).release_value())