Skip to content

Commit

Permalink
#161 add special treatment for std::vector footprinting
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrzebonski committed Oct 8, 2021
1 parent cd61c8b commit 7184e53
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions src/checkpoint/container/vector_serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ namespace checkpoint {

template <typename SerializerT, typename T, typename VectorAllocator>
typename std::enable_if_t<
not std::is_same<SerializerT, checkpoint::Footprinter>::value, SerialSizeType
not std::is_same<SerializerT, checkpoint::Footprinter>::value,
SerialSizeType
>
serializeVectorMeta(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
SerialSizeType vec_capacity = vec.capacity();
Expand All @@ -68,15 +69,6 @@ serializeVectorMeta(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
return vec_size;
}

template <typename SerializerT, typename T, typename VectorAllocator>
typename std::enable_if_t<
std::is_same<SerializerT, checkpoint::Footprinter>::value, SerialSizeType
>
serializeVectorMeta(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
s.countBytes(vec);
return vec.size();
}

template <typename T, typename VectorAllocator>
void constructVectorData(
SerialSizeType const vec_size, std::vector<T, VectorAllocator>& vec,
Expand Down Expand Up @@ -117,27 +109,27 @@ void constructVectorData(
}
}

template <typename Serializer, typename T, typename VectorAllocator>
void serialize(Serializer& s, std::vector<T, VectorAllocator>& vec) {
template <typename SerializerT, typename T, typename VectorAllocator>
typename std::enable_if_t<
not std::is_same<SerializerT, checkpoint::Footprinter>::value,
void
>
serialize(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
auto const vec_size = serializeVectorMeta(s, vec);

if (s.isUnpacking()) {
constructVectorData(vec_size, vec);
}

dispatch::serializeArray(s, vec.data(), vec.size());

// make sure to account for reserved space when footprinting
s.addBytes(sizeof(T) * (vec.capacity() - vec.size()));
}

template <typename Serializer, typename VectorAllocator>
void serialize(Serializer& s, std::vector<bool, VectorAllocator>& vec) {
if (s.isFootprinting()) {
s.countBytes(vec);
return;
}

template <typename SerializerT, typename VectorAllocator>
typename std::enable_if_t<
not std::is_same<SerializerT, checkpoint::Footprinter>::value,
void
>
serialize(SerializerT& s, std::vector<bool, VectorAllocator>& vec) {
auto const vec_size = serializeVectorMeta(s, vec);

if (s.isUnpacking()) {
Expand All @@ -157,6 +149,26 @@ void serialize(Serializer& s, std::vector<bool, VectorAllocator>& vec) {
}
}

template <typename SerializerT, typename T, typename VectorAllocator>
typename std::enable_if_t<
std::is_same<SerializerT, checkpoint::Footprinter>::value,
void
>
serialize(SerializerT& s, std::vector<T, VectorAllocator>& vec) {
s.countBytes(vec);
dispatch::serializeArray(s, vec.data(), vec.size());
s.addBytes(sizeof(T) * (vec.capacity() - vec.size()));
}

template <typename SerializerT, typename VectorAllocator>
typename std::enable_if_t<
std::is_same<SerializerT, checkpoint::Footprinter>::value, void
>
serialize(SerializerT& s, std::vector<bool, VectorAllocator>& vec) {
s.countBytes(vec);
return;
}

} /* end namespace checkpoint */

#endif /*INCLUDED_CHECKPOINT_CONTAINER_VECTOR_SERIALIZE_H*/

0 comments on commit 7184e53

Please sign in to comment.