Merge pull request #5021

b82efa32 epee: speed up json parsing (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2019-01-16 21:37:29 +02:00
commit a093a7569e
No known key found for this signature in database
GPG Key ID: 55432DF31CCD4FCD
2 changed files with 13 additions and 3 deletions

View File

@ -31,7 +31,8 @@
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/any.hpp> #include <boost/any.hpp>
#include <string> #include <string>
#include <list> #include <vector>
#include <deque>
#define PORTABLE_STORAGE_SIGNATUREA 0x01011101 #define PORTABLE_STORAGE_SIGNATUREA 0x01011101
#define PORTABLE_STORAGE_SIGNATUREB 0x01020101 // bender's nightmare #define PORTABLE_STORAGE_SIGNATUREB 0x01020101 // bender's nightmare
@ -71,6 +72,9 @@ namespace epee
{ {
struct section; 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(); return m_array.back();
} }
std::list<t_entry_type> m_array; void reserve(size_t n)
mutable typename std::list<t_entry_type>::const_iterator m_it; {
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;
}; };

View File

@ -136,6 +136,7 @@ namespace epee
//for pod types //for pod types
array_entry_t<type_name> sa; array_entry_t<type_name> sa;
size_t size = read_varint(); size_t size = read_varint();
sa.reserve(size);
//TODO: add some optimization here later //TODO: add some optimization here later
while(size--) while(size--)
sa.m_array.push_back(read<type_name>()); sa.m_array.push_back(read<type_name>());