mirror of
https://github.com/yuzu-emu/sirit
synced 2024-11-22 14:53:41 +00:00
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:
parent
59f795bd6d
commit
f7c4b07a7e
1 changed files with 2 additions and 4 deletions
|
@ -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));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue