aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-01-16 21:37:29 +0200
committerRiccardo Spagni <ric@spagni.net>2019-01-16 21:37:29 +0200
commita093a7569e798134f405fdefeb8bebadae05cdf3 (patch)
treeebbfb262d13d52942a3c337e61ef3ddb305391f7 /contrib
parentMerge pull request #5019 (diff)
parentepee: speed up json parsing (diff)
downloadmonero-a093a7569e798134f405fdefeb8bebadae05cdf3.tar.xz
Merge pull request #5021
b82efa32 epee: speed up json parsing (moneromooo-monero)
Diffstat (limited to 'contrib')
-rw-r--r--contrib/epee/include/storages/portable_storage_base.h15
-rw-r--r--contrib/epee/include/storages/portable_storage_from_bin.h1
2 files changed, 13 insertions, 3 deletions
diff --git a/contrib/epee/include/storages/portable_storage_base.h b/contrib/epee/include/storages/portable_storage_base.h
index 93132548b..da84fd8ea 100644
--- a/contrib/epee/include/storages/portable_storage_base.h
+++ b/contrib/epee/include/storages/portable_storage_base.h
@@ -31,7 +31,8 @@
#include <boost/variant.hpp>
#include <boost/any.hpp>
#include <string>
-#include <list>
+#include <vector>
+#include <deque>
#define PORTABLE_STORAGE_SIGNATUREA 0x01011101
#define PORTABLE_STORAGE_SIGNATUREB 0x01020101 // bender's nightmare
@@ -71,6 +72,9 @@ namespace epee
{
struct section;
+ template<typename T> struct entry_container { typedef std::vector<T> type; static void reserve(type &t, size_t n) { t.reserve(n); } };
+ template<> struct entry_container<bool> { typedef std::deque<bool> type; static void reserve(type &t, size_t n) {} };
+
/************************************************************************/
/* */
/************************************************************************/
@@ -119,8 +123,13 @@ namespace epee
return m_array.back();
}
- std::list<t_entry_type> m_array;
- mutable typename std::list<t_entry_type>::const_iterator m_it;
+ void reserve(size_t n)
+ {
+ entry_container<t_entry_type>::reserve(m_array, n);
+ }
+
+ typename entry_container<t_entry_type>::type m_array;
+ mutable typename entry_container<t_entry_type>::type::const_iterator m_it;
};
diff --git a/contrib/epee/include/storages/portable_storage_from_bin.h b/contrib/epee/include/storages/portable_storage_from_bin.h
index f9cc22d27..2884f8c5e 100644
--- a/contrib/epee/include/storages/portable_storage_from_bin.h
+++ b/contrib/epee/include/storages/portable_storage_from_bin.h
@@ -136,6 +136,7 @@ namespace epee
//for pod types
array_entry_t<type_name> sa;
size_t size = read_varint();
+ sa.reserve(size);
//TODO: add some optimization here later
while(size--)
sa.m_array.push_back(read<type_name>());