mirror of
https://github.com/yuzu-emu/sirit.git
synced 2024-11-25 16:55:42 +01: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
@ -13,11 +13,9 @@ Stream::Stream(std::vector<u8>& bytes) : bytes(bytes) {}
|
|||||||
Stream::~Stream() = default;
|
Stream::~Stream() = default;
|
||||||
|
|
||||||
void Stream::Write(std::string_view string) {
|
void Stream::Write(std::string_view string) {
|
||||||
|
bytes.insert(bytes.end(), string.begin(), string.end());
|
||||||
|
|
||||||
const auto size{string.size()};
|
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++) {
|
for (std::size_t i = 0; i < 4 - size % 4; i++) {
|
||||||
Write(static_cast<u8>(0));
|
Write(static_cast<u8>(0));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user