mirror of
https://github.com/monero-project/monero.git
synced 2025-05-06 16:55:29 -04:00
Improved performance for epee serialization:
- Removed copy of field names in binary deserialization - Removed copy of array values in binary deserialization - Removed copy of string values in json deserialization - Removed unhelpful allocation in json string value parsing - Removed copy of blob data on binary and json serialization
This commit is contained in:
parent
411f1b0ee3
commit
a9bdc6e4c4
7 changed files with 56 additions and 59 deletions
|
@ -46,24 +46,12 @@ namespace epee
|
|||
namespace serialization
|
||||
{
|
||||
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_type, class t_storage>
|
||||
static bool serialize_t_val(const t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
return stg.set_value(pname, d, hparent_section);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_type, class t_storage>
|
||||
static bool unserialize_t_val(t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
return stg.get_value(pname, d, hparent_section);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_type, class t_storage>
|
||||
static bool serialize_t_val_as_blob(const t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
std::string blob((const char *)&d, sizeof(d));
|
||||
return stg.set_value(pname, blob, hparent_section);
|
||||
return stg.set_value(pname, std::move(blob), hparent_section);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_type, class t_storage>
|
||||
|
@ -114,13 +102,15 @@ namespace epee
|
|||
template<class stl_container, class t_storage>
|
||||
static bool serialize_stl_container_t_val (const stl_container& container, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
using value_type = typename stl_container::value_type;
|
||||
|
||||
if(!container.size()) return true;
|
||||
typename stl_container::const_iterator it = container.begin();
|
||||
typename t_storage::harray hval_array = stg.insert_first_value(pname, *it, hparent_section);
|
||||
typename t_storage::harray hval_array = stg.insert_first_value(pname, value_type(*it), hparent_section);
|
||||
CHECK_AND_ASSERT_MES(hval_array, false, "failed to insert first value to storage");
|
||||
it++;
|
||||
for(;it!= container.end();it++)
|
||||
stg.insert_next_value(hval_array, *it);
|
||||
stg.insert_next_value(hval_array, value_type(*it));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -149,7 +139,7 @@ namespace epee
|
|||
*p_elem = v;
|
||||
p_elem++;
|
||||
}
|
||||
return stg.set_value(pname, mb, hparent_section);
|
||||
return stg.set_value(pname, std::move(mb), hparent_section);
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------------------------------
|
||||
template<class stl_container, class t_storage>
|
||||
|
@ -221,7 +211,7 @@ namespace epee
|
|||
template<class t_type, class t_storage>
|
||||
static bool kv_serialize(const t_type& d, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
|
||||
{
|
||||
return stg.set_value(pname, d, hparent_section);
|
||||
return stg.set_value(pname, t_type(d), hparent_section);
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_type, class t_storage>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue