epee: resize vectors where possible in serialization

to avoid unnecessary repeated reallocation
pull/105/head
moneromooo-monero 6 years ago committed by wowario
parent c4bdd5699c
commit 47f7cf68ae
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111

@ -35,6 +35,11 @@
namespace epee
{
namespace
{
template<class C> void hint_resize(C &container, size_t size) {}
template<class C> void hint_resize(std::vector<C> &container, size_t size) { container.reserve(size); }
}
namespace serialization
{
@ -158,6 +163,7 @@ namespace epee
false,
"size in blob " << loaded_size << " not have not zero modulo for sizeof(value_type) = " << sizeof(typename stl_container::value_type));
size_t count = (loaded_size/sizeof(typename stl_container::value_type));
hint_resize(container, count);
for(size_t i = 0; i < count; i++)
container.insert(container.end(), *(pelem++));
}

Loading…
Cancel
Save