From 29dea030916f38348f4c382848fa021afcc84a9f Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 16 Aug 2018 18:15:07 +0000 Subject: epee: resize vectors where possible in serialization to avoid unnecessary repeated reallocation --- .../epee/include/serialization/keyvalue_serialization_overloads.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'contrib/epee/include') 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 void hint_resize(C &container, size_t size) {} + template void hint_resize(std::vector &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++)); } -- cgit v1.2.3