diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-08-16 18:15:07 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-08-17 01:08:52 +0000 |
commit | 29dea030916f38348f4c382848fa021afcc84a9f (patch) | |
tree | 3ae87434cfe7d99a1ccc68c29f10e7704d38c7da /contrib/epee/include/serialization | |
parent | Merge pull request #4191 (diff) | |
download | monero-29dea030916f38348f4c382848fa021afcc84a9f.tar.xz |
epee: resize vectors where possible in serialization
to avoid unnecessary repeated reallocation
Diffstat (limited to 'contrib/epee/include/serialization')
-rw-r--r-- | contrib/epee/include/serialization/keyvalue_serialization_overloads.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index 09087f785..15c95f07a 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h +++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h @@ -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) << ", type " << typeid(typename stl_container::value_type).name()); 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++)); } |