Replace std::memcpy with a more expressive alternative

This commit is contained in:
Chris Thrasher 2023-10-29 18:15:55 -06:00
parent f588589089
commit b16114fa23
2 changed files with 6 additions and 8 deletions

View File

@ -133,11 +133,9 @@ private:
// (so we protect any operation on it with the mutex) // (so we protect any operation on it with the mutex)
{ {
const std::lock_guard lock(m_mutex); const std::lock_guard lock(m_mutex);
const std::size_t oldSize = m_samples.size(); const auto* begin = static_cast<const char*>(packet.getData()) + 1;
m_samples.resize(oldSize + sampleCount); const auto* end = begin + sampleCount * sizeof(std::int16_t);
std::memcpy(&(m_samples[oldSize]), m_samples.insert(m_samples.end(), begin, end);
static_cast<const char*>(packet.getData()) + 1,
sampleCount * sizeof(std::int16_t));
} }
} }
else if (id == serverEndOfStream) else if (id == serverEndOfStream)

View File

@ -66,9 +66,9 @@ void Packet::append(const void* data, std::size_t sizeInBytes)
{ {
if (data && (sizeInBytes > 0)) if (data && (sizeInBytes > 0))
{ {
const std::size_t start = m_data.size(); const auto* begin = reinterpret_cast<const std::byte*>(data);
m_data.resize(start + sizeInBytes); const auto* end = begin + sizeInBytes;
std::memcpy(&m_data[start], data, sizeInBytes); m_data.insert(m_data.end(), begin, end);
} }
} }