diff options
author | Lioncash <[email protected]> | 2019-03-16 00:17:18 -0400 |
---|---|---|
committer | ReinUsesLisp <[email protected]> | 2019-03-16 02:51:35 -0300 |
commit | f7c4b07a7e14edb1dcd93bc9879c823423705c2e (patch) | |
tree | 2d3352fd3ea8ff680dd00fba84bc4df6c117c6cb /src/stream.cpp | |
parent | 59f795bd6d64e905649899f5ce542081241fec72 (diff) | |
download | sirit-f7c4b07a7e14edb1dcd93bc9879c823423705c2e.tar.gz sirit-f7c4b07a7e14edb1dcd93bc9879c823423705c2e.zip |
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.
Diffstat (limited to 'src/stream.cpp')
-rw-r--r-- | src/stream.cpp | 6 |
1 files 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<u8>& 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<const u8*>(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<u8>(0)); } |