From f7c4b07a7e14edb1dcd93bc9879c823423705c2e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sat, 16 Mar 2019 00:17:18 -0400 Subject: [PATCH] stream: Insert supplied string in one operation Like the other overloads, we can insert the whole string within one operation instead of doing a byte-by-byte append. We only do byte-by-byte appending when padding is necessary. --- src/stream.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/stream.cpp b/src/stream.cpp index d171830..8cac8cb 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -13,11 +13,9 @@ Stream::Stream(std::vector& bytes) : bytes(bytes) {} Stream::~Stream() = default; void Stream::Write(std::string_view string) { + bytes.insert(bytes.end(), string.begin(), string.end()); + const auto size{string.size()}; - const auto data{reinterpret_cast(string.data())}; - for (std::size_t i = 0; i < size; i++) { - Write(data[i]); - } for (std::size_t i = 0; i < 4 - size % 4; i++) { Write(static_cast(0)); }