Skip to content

Commit

Permalink
Avoid generating useless JSON string
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sparus committed May 11, 2024
1 parent 3e1aec4 commit a3acbee
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 162 deletions.
24 changes: 14 additions & 10 deletions immer/extra/archive/json/archivable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ struct archivable
// }
};

template <class Storage, class Names, class Container>
template <class Previous, class Storage, class Names, class Container>
auto save_minimal(
const json_immer_output_archive<detail::archives_save<Storage, Names>>& ar,
const json_immer_output_archive<Previous,
detail::archives_save<Storage, Names>>& ar,
const archivable<Container>& value)
{
auto& save_archive =
const_cast<
json_immer_output_archive<detail::archives_save<Storage, Names>>&>(
json_immer_output_archive<Previous,
detail::archives_save<Storage, Names>>&>(
ar)
.get_output_archives()
.template get_save_archive<Container>();
Expand All @@ -110,24 +112,26 @@ auto save_minimal(const json_immer_auto_output_archive<Archive, WrapF>& ar,

// This function must exist because cereal does some checks and it's not
// possible to have only load_minimal for a type without having save_minimal.
template <class Storage, class Names, class Container>
template <class Previous, class Storage, class Names, class Container>
auto save_minimal(
const json_immer_output_archive<detail::archives_load<Storage, Names>>& ar,
const json_immer_output_archive<Previous,
detail::archives_load<Storage, Names>>& ar,
const archivable<Container>& value) ->
typename container_traits<Container>::container_id::rep_t
{
throw std::logic_error{"Should never be called"};
}

template <class ImmerArchives, class Container>
template <class Previous, class ImmerArchives, class Container>
void load_minimal(
const json_immer_input_archive<ImmerArchives>& ar,
const json_immer_input_archive<Previous, ImmerArchives>& ar,
archivable<Container>& value,
const typename container_traits<Container>::container_id::rep_t& id)
{
auto& loader = const_cast<json_immer_input_archive<ImmerArchives>&>(ar)
.get_input_archives()
.template get_loader<Container>();
auto& loader =
const_cast<json_immer_input_archive<Previous, ImmerArchives>&>(ar)
.get_input_archives()
.template get_loader<Container>();

// Have to be specific because for vectors container_id is different from
// node_id, but for hash-based containers, a container is identified just by
Expand Down
Loading

0 comments on commit a3acbee

Please sign in to comment.