From 47f7cf68aeaf51838cc794297e4693fc94a80275 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 16 Aug 2018 18:15:07 +0000 Subject: [PATCH] epee: resize vectors where possible in serialization to avoid unnecessary repeated reallocation --- .../serialization/keyvalue_serialization_overloads.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h index 7087136cc..db4b1af5e 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)); 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++)); }