diff --git a/rpcs3/util/serialization.hpp b/rpcs3/util/serialization.hpp index 16b164c69e..df002d974b 100644 --- a/rpcs3/util/serialization.hpp +++ b/rpcs3/util/serialization.hpp @@ -132,8 +132,18 @@ public: if (is_writing()) { - ensure(pos == data_offset + data.size()); - const auto ptr = reinterpret_cast(memory_provider()); + ensure(pos <= data_offset + data.size()); + + const auto ptr = reinterpret_cast(memory_provider()); + + if (pos != data_offset + data.size()) + { + data.insert(data.begin() + pos - data_offset, ptr, ptr + size); + pos += size; + return true;- + } + + // Seems to be much faster than data.begin() + pos on MSVC data.insert(data.end(), ptr, ptr + size); pos += size; return true; @@ -521,7 +531,7 @@ public: usz get_size(usz recommended = umax) const { recommended = std::min(recommended, m_max_data); - return std::min(m_max_data, m_file_handler ? m_file_handler->get_size(*this, recommended) : data_offset + data.size()); + return std::min(m_max_data, m_file_handler ? m_file_handler->get_size(*this, recommended) : (data.empty() ? 0 : data_offset + data.size())); } template requires (Bitcopy) @@ -557,7 +567,7 @@ public: } template requires (std::is_copy_constructible_v && std::is_constructible_v && Bitcopy) - std::pair try_read() +6 std::pair try_read() { if (is_writing()) {