Savestates/vm: Improve saving performance

This commit is contained in:
Eladash 2024-01-01 09:13:16 +02:00 committed by Elad Ashkenazi
parent f0c93ae9dc
commit 858e493b52
2 changed files with 7 additions and 11 deletions

View File

@ -1665,13 +1665,13 @@ namespace vm
ar.breathe(); ar.breathe();
for (usz iter_count = 0; size; iter_count++, ptr += byte_of_pages) for (usz iter_count = 0; size; iter_count += sizeof(u32), ptr += byte_of_pages * sizeof(u32))
{ {
size -= byte_of_pages; const u32 bitmap = read_from_ptr<le_t<u32>>(bit_array, iter_count);
const u8 bitmap = bit_array[iter_count]; size -= byte_of_pages * sizeof(bitmap);
for (usz i = 0; i < byte_of_pages;) for (usz i = 0; i < byte_of_pages * sizeof(bitmap);)
{ {
usz block_count = 0; usz block_count = 0;

View File

@ -109,11 +109,7 @@ public:
// Reserve memory for serialization // Reserve memory for serialization
void reserve(usz size) void reserve(usz size)
{ {
// Is a NO-OP for deserialization in order to allow usage from serialization specializations regardless data.reserve(data.size() + size);
if (is_writing())
{
data.reserve(data.size() + size);
}
} }
template <typename Func> requires (std::is_convertible_v<std::invoke_result_t<Func>, const void*>) template <typename Func> requires (std::is_convertible_v<std::invoke_result_t<Func>, const void*>)
@ -136,9 +132,9 @@ public:
if (is_writing()) if (is_writing())
{ {
ensure(pos >= data_offset); ensure(pos == data_offset + data.size());
const auto ptr = reinterpret_cast<const u8*>(memory_provider()); const auto ptr = reinterpret_cast<const u8*>(memory_provider());
data.insert(data.begin() + (pos - data_offset), ptr, ptr + size); data.insert(data.end(), ptr, ptr + size);
pos += size; pos += size;
return true; return true;
} }