From 1a46823ec59b0ad4556e494c0488d5a8160aa19b Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 30 Jun 2023 21:50:44 -0400 Subject: parcel: Optimize small_vector sizes --- src/core/hle/service/nvnflinger/parcel.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/core') diff --git a/src/core/hle/service/nvnflinger/parcel.h b/src/core/hle/service/nvnflinger/parcel.h index 23ba315a0..e2c9bbd50 100644 --- a/src/core/hle/service/nvnflinger/parcel.h +++ b/src/core/hle/service/nvnflinger/parcel.h @@ -6,6 +6,7 @@ #include #include #include + #include #include "common/alignment.h" @@ -148,9 +149,9 @@ public: this->WriteImpl(0U, m_object_buffer); } - std::vector Serialize() const { - std::vector output_buffer(sizeof(ParcelHeader) + m_data_buffer.size() + - m_object_buffer.size()); + std::span Serialize() { + m_output_buffer.resize(sizeof(ParcelHeader) + m_data_buffer.size() + + m_object_buffer.size()); ParcelHeader header{}; header.data_size = static_cast(m_data_buffer.size()); @@ -158,17 +159,17 @@ public: header.objects_size = static_cast(m_object_buffer.size()); header.objects_offset = header.data_offset + header.data_size; - std::memcpy(output_buffer.data(), &header, sizeof(header)); - std::ranges::copy(m_data_buffer, output_buffer.data() + header.data_offset); - std::ranges::copy(m_object_buffer, output_buffer.data() + header.objects_offset); + std::memcpy(m_output_buffer.data(), &header, sizeof(ParcelHeader)); + std::ranges::copy(m_data_buffer, m_output_buffer.data() + header.data_offset); + std::ranges::copy(m_object_buffer, m_output_buffer.data() + header.objects_offset); - return output_buffer; + return m_output_buffer; } private: - template + template requires(std::is_trivially_copyable_v) - void WriteImpl(const T& val, boost::container::small_vector& buffer) { + void WriteImpl(const T& val, boost::container::small_vector& buffer) { const size_t aligned_size = Common::AlignUp(sizeof(T), 4); const size_t old_size = buffer.size(); buffer.resize(old_size + aligned_size); @@ -177,8 +178,9 @@ private: } private: - boost::container::small_vector m_data_buffer; - boost::container::small_vector m_object_buffer; + boost::container::small_vector m_data_buffer; + boost::container::small_vector m_object_buffer; + boost::container::small_vector m_output_buffer; }; } // namespace Service::android -- cgit v1.2.3