aboutsummaryrefslogtreecommitdiff
path: root/src/serialization/json_object.h
diff options
context:
space:
mode:
authorAlexander Blair <snipa@jagtech.io>2020-08-16 12:43:10 -0700
committerAlexander Blair <snipa@jagtech.io>2020-08-16 12:43:11 -0700
commit009ca6fcd31a6152120692dca7392008091c5e94 (patch)
tree2bef7d5b95911b86054c6669209a30a36b9158eb /src/serialization/json_object.h
parent9eebe01c58f4a99ae350148ecc86aa8159e53b4e (diff)
parent98c151ecb8dd887ef9ade5442de467875b8f16f5 (diff)
downloadmonzero-core-009ca6fcd31a6152120692dca7392008091c5e94.tar.gz
monzero-core-009ca6fcd31a6152120692dca7392008091c5e94.tar.xz
monzero-core-009ca6fcd31a6152120692dca7392008091c5e94.zip
Merge pull request #6601
98c151ecb Optimize ZMQ-JSON vector reading; GetBlocksFast reads 24%+ faster (Lee Clagett) 60627c9f2 Switch to insitu parsing for ZMQ-JSON; GetBlocksFast reads 13%+ faster (Lee Clagett) fe96e66eb Fix pruned tx for ZMQ's GetBlocksFast (Lee Clagett)
Diffstat (limited to 'src/serialization/json_object.h')
-rw-r--r--src/serialization/json_object.h24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/serialization/json_object.h b/src/serialization/json_object.h
index e016bef41..b5d0f1508 100644
--- a/src/serialization/json_object.h
+++ b/src/serialization/json_object.h
@@ -32,6 +32,7 @@
#include <cstring>
#include <rapidjson/document.h>
#include <rapidjson/writer.h>
+#include <vector>
#include "byte_stream.h"
#include "cryptonote_basic/cryptonote_basic.h"
@@ -277,6 +278,8 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResp
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig& i);
void fromJsonValue(const rapidjson::Value& val, rct::rctSig& sig);
+void fromJsonValue(const rapidjson::Value& val, rct::ctkey& key);
+
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::ecdhTuple& tuple);
void fromJsonValue(const rapidjson::Value& val, rct::ecdhTuple& tuple);
@@ -339,6 +342,7 @@ inline typename std::enable_if<sfinae::is_map_like<Map>::value, void>::type from
auto itr = val.MemberBegin();
+ map.clear();
while (itr != val.MemberEnd())
{
typename Map::key_type k;
@@ -359,6 +363,19 @@ inline typename std::enable_if<sfinae::is_vector_like<Vec>::value, void>::type t
dest.EndArray();
}
+namespace traits
+{
+ template<typename T>
+ void reserve(const T&, std::size_t)
+ {}
+
+ template<typename T>
+ void reserve(std::vector<T>& vec, const std::size_t count)
+ {
+ vec.reserve(count);
+ }
+}
+
template <typename Vec>
inline typename std::enable_if<sfinae::is_vector_like<Vec>::value, void>::type fromJsonValue(const rapidjson::Value& val, Vec& vec)
{
@@ -367,11 +384,12 @@ inline typename std::enable_if<sfinae::is_vector_like<Vec>::value, void>::type f
throw WRONG_TYPE("json array");
}
+ vec.clear();
+ traits::reserve(vec, val.Size());
for (rapidjson::SizeType i=0; i < val.Size(); i++)
{
- typename Vec::value_type v;
- fromJsonValue(val[i], v);
- vec.push_back(v);
+ vec.emplace_back();
+ fromJsonValue(val[i], vec.back());
}
}