From 3c88eec853ed7e81c6f36e11adeb73ed7b244624 Mon Sep 17 00:00:00 2001 From: vimes Date: Thu, 8 Aug 2024 14:57:35 +0300 Subject: [PATCH] review cleanup --- common/stream.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/common/stream.h b/common/stream.h index f3367960..7034cf63 100644 --- a/common/stream.h +++ b/common/stream.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -291,9 +290,7 @@ inline stream_in_t::stream_in_t(const std::vector& buffer) : template inline void stream_in_t::pop(TType& value) { - if constexpr (std::is_trivially_copyable_v && - !(std::is_pointer_v || - std::is_reference_v)) + if constexpr (std::is_trivially_copyable_v) { if (inBuffer.size() - inPosition < sizeof(TType)) { @@ -327,7 +324,7 @@ inline void stream_in_t::pop(char* buffer, uint64_t bufferSize) return; } - memcpy(buffer, &this->inBuffer[inPosition], bufferSize); + std::copy(&this->inBuffer[inPosition], &this->inBuffer[inPosition] + bufferSize, buffer); inPosition += bufferSize; } @@ -348,7 +345,7 @@ inline void stream_in_t::pop(std::string& value) return; } - value = std::string(reinterpret_cast(&this->inBuffer[inPosition]), size); + value.assign(reinterpret_cast(&this->inBuffer[inPosition]), size); inPosition += size; } @@ -562,13 +559,10 @@ inline stream_out_t::stream_out_t() template inline void stream_out_t::push(const TType& value) { - if constexpr (std::is_trivially_copyable_v && - !(std::is_pointer_v || - std::is_reference_v)) + if constexpr (std::is_trivially_copyable_v) { - integer_t size = outBuffer.size(); - outBuffer.resize(size + sizeof(TType)); - reinterpret_cast(outBuffer[size]) = value; + auto& data = reinterpret_cast(value); + outBuffer.insert(outBuffer.end(), std::begin(data), std::end(data)); } else { @@ -582,9 +576,7 @@ inline void stream_out_t::push(const char* buffer, uint64_t bufferSize) { return; } - integer_t size = outBuffer.size(); - outBuffer.resize(size + bufferSize); - memcpy(&outBuffer[size], buffer, bufferSize); + outBuffer.insert(outBuffer.end(), buffer, buffer + bufferSize); } inline void stream_out_t::push(const std::string& value)