mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-23 11:23:26 +01:00
epee: resize vectors where possible in serialization
to avoid unnecessary repeated reallocation
This commit is contained in:
parent
b780cf4db1
commit
29dea03091
@ -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) << ", type " << typeid(typename stl_container::value_type).name());
|
"size in blob " << loaded_size << " not have not zero modulo for sizeof(value_type) = " << sizeof(typename stl_container::value_type) << ", type " << typeid(typename stl_container::value_type).name());
|
||||||
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
Block a user