epee: resize vectors where possible in serialization

to avoid unnecessary repeated reallocation
This commit is contained in:
moneromooo-monero 2018-08-16 18:15:07 +00:00 committed by wowario
parent c4bdd5699c
commit 47f7cf68ae
No known key found for this signature in database
GPG Key ID: 24DCBE762DE9C111
1 changed files with 6 additions and 0 deletions

View File

@ -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++));
}