diff --git a/lager/extra/cereal/immer_table.hpp b/lager/extra/cereal/immer_table.hpp index 4161487e..681deb35 100644 --- a/lager/extra/cereal/immer_table.hpp +++ b/lager/extra/cereal/immer_table.hpp @@ -15,57 +15,44 @@ #include #include - #include -#include -#include namespace cereal { -// This code has mostly been adapted from -// We don't deal for now with data that could be potentially serialized -// directly in binary format. template -void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, - const immer::table& table) +void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, immer::table& m) { - ar(make_size_tag(static_cast(table.size()))); - for (auto&& v : table) - ar(v); + size_type size; + ar(make_size_tag(size)); + + for (auto i = size_type{}; i < size; ++i) { + T x; + ar(x); + m = std::move(m).insert(std::move(x)); + } + if (size != m.size()) + throw std::runtime_error{"duplicate ids?"}; } template -void CEREAL_LOAD_FUNCTION_NAME(Archive& ar, - immer::table& table) +void CEREAL_SAVE_FUNCTION_NAME(Archive& ar, + const immer::table& m) { - size_type size{}; - ar(make_size_tag(size)); - - if (!size) - return; - - auto t = immer::table{}.transient(); - - for (auto i = size_type{}; i < size; ++i) { - T x; - ar(x); - t.insert(std::move(x)); - } - table = std::move(t).persistent(); - - assert(size == table.size()); + ar(make_size_tag(static_cast(m.size()))); + for (auto&& v : m) + ar(v); } } // namespace cereal