diff --git a/src/common/fifo_queue.h b/src/common/fifo_queue.h index 7ccbaf109..18d74c9c7 100644 --- a/src/common/fifo_queue.h +++ b/src/common/fifo_queue.h @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin // SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) #pragma once @@ -71,7 +71,7 @@ public: } // faster version of push_back_range for POD types which can be memcpy()ed - template&& std::is_trivial_v, int> = 0> + template && std::is_trivial_v, int> = 0> void PushRange(const T* data, u32 size) { DebugAssert((m_size + size) <= CAPACITY); @@ -137,10 +137,25 @@ public: return val; } + template && std::is_trivial_v, int> = 0> void PopRange(T* out_data, u32 count) { DebugAssert(m_size >= count); + do + { + const u32 contig_count = std::min(count, CAPACITY - m_head); + std::memcpy(out_data, &m_ptr[m_head], sizeof(T) * contig_count); + out_data += contig_count; + m_head = (m_head + contig_count) % CAPACITY; + m_size -= contig_count; + count -= contig_count; + } while (count > 0); + } + template || !std::is_trivial_v, int> = 0> + void PopRange(T* out_data, u32 count) + { + DebugAssert(m_size >= count); for (u32 i = 0; i < count; i++) { out_data[i] = std::move(m_ptr[m_head]);