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.
This commit is contained in:
Lioncash 2019-03-16 00:17:18 -04:00 committed by ReinUsesLisp
parent 59f795bd6d
commit f7c4b07a7e

View file

@ -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));
}