epee: resize vectors where possible in serialization
to avoid unnecessary repeated reallocation
This commit is contained in:
parent
c4bdd5699c
commit
47f7cf68ae
|
@ -35,6 +35,11 @@
|
||||||
|
|
||||||
namespace epee
|
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
|
namespace serialization
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -158,6 +163,7 @@ namespace epee
|
||||||
false,
|
false,
|
||||||
"size in blob " << loaded_size << " not have not zero modulo for sizeof(value_type) = " << sizeof(typename stl_container::value_type));
|
"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));
|
size_t count = (loaded_size/sizeof(typename stl_container::value_type));
|
||||||
|
hint_resize(container, count);
|
||||||
for(size_t i = 0; i < count; i++)
|
for(size_t i = 0; i < count; i++)
|
||||||
container.insert(container.end(), *(pelem++));
|
container.insert(container.end(), *(pelem++));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue