-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#161 use reconstruction logic for std::vector #214
#161 use reconstruction logic for std::vector #214
Conversation
326eac6
to
2a37326
Compare
In general, I took reconstruct code almost 1:1 to be able to pass reconstruct tag directly to emplace_back(). Without that I would have to do template <typename T, typename VectorAllocator>
void reconstructVectorData(
SerialSizeType const vec_size, std::vector<T, VectorAllocator>& vec) {
auto* buf = dispatch::Standard::allocate<T>();
for (SerialSizeType i = 0; i < vec_size; ++i) {
auto* t = dispatch::Standard::construct<T>(buf);
vec.emplace_back(std::move(*t));
}
} |
@lifflander Do you think that's (more or less) the direction we wanted to head? |
c10c363
to
1ea3f1f
Compare
I think |
Codecov Report
@@ Coverage Diff @@
## develop #214 +/- ##
===========================================
+ Coverage 94.14% 94.32% +0.17%
===========================================
Files 100 102 +2
Lines 3093 3187 +94
===========================================
+ Hits 2912 3006 +94
Misses 181 181
|
Sorry I was slow to reply. I agree with @PhilMiller that doing the resize is probably preferable for optimization. |
984b3cd
to
51efb95
Compare
51efb95
to
da6c6d7
Compare
5298aca
to
7184e53
Compare
7184e53
to
3c7e20f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the approach makes sense. The only overload that might be improved by another issue is the vector case that seems very un-optimized.
> deserializeOrderedElems( | ||
std::is_same<Serializer, checkpoint::Footprinter>::value, void | ||
> | ||
deserializeOrderedElems( | ||
Serializer& s, ContainerT& cont, typename ContainerT::size_type size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A potential refactoring, based on comments I had pointed out to me elsewhere: this case can avoid using enable_if
, and just be an overload taking checkpoint::Footprinter
rather than templating over Serializer
at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same applies for related cases in the other files, too.
std::is_same<SerializerT, checkpoint::Footprinter>::value, void | ||
> | ||
serialize(SerializerT& s, std::vector<bool, VectorAllocator>& vec) { | ||
s.countBytes(vec); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could/should also s.addBytes(vec.capacity()*sizeof(bool))
or s.addBytes(vec.capacity()*sizeof(bool)/CHAR_BIT)
.
I'm unconcerned which exactly, but I'd like something whose resulting value is O(N)
so that if we or an application have code with an overgrown vector<bool>
, it shows up.
Fixes #161