[core] Use convertJSON instead of RapidJSON directly
This commit is contained in:
@@ -4,19 +4,14 @@
|
||||
|
||||
#include <mbgl/style/function/source_function.hpp>
|
||||
|
||||
#include <mbgl/style/rapidjson_conversion.hpp>
|
||||
#include <mbgl/style/conversion.hpp>
|
||||
#include <mbgl/style/conversion/json.hpp>
|
||||
#include <mbgl/style/conversion/function.hpp>
|
||||
|
||||
#include <rapidjson/document.h>
|
||||
|
||||
|
||||
using namespace mbgl;
|
||||
using namespace mbgl::style;
|
||||
|
||||
static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> createFunctionJSON(size_t stopCount) {
|
||||
rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> doc;
|
||||
|
||||
static std::string createFunctionJSON(size_t stopCount) {
|
||||
std::string stops = "[";
|
||||
for (size_t i = 0; i < stopCount; i++) {
|
||||
std::string value = std::to_string(100.0f / stopCount * i);
|
||||
@@ -24,9 +19,7 @@ static rapidjson::GenericDocument<rapidjson::UTF8<>, rapidjson::CrtAllocator> cr
|
||||
stops += "[" + value + ", " + value + "]";
|
||||
}
|
||||
stops += "]";
|
||||
|
||||
doc.Parse<0>(R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})");
|
||||
return doc;
|
||||
return R"({"type": "exponential", "base": 2, "stops": )" + stops + R"(, "property": "x"})";
|
||||
}
|
||||
|
||||
static void Parse_SourceFunction(benchmark::State& state) {
|
||||
@@ -37,7 +30,7 @@ static void Parse_SourceFunction(benchmark::State& state) {
|
||||
state.PauseTiming();
|
||||
auto doc = createFunctionJSON(stopCount);
|
||||
state.ResumeTiming();
|
||||
optional<SourceFunction<float>> result = conversion::convert<SourceFunction<float>, JSValue>(doc, error);
|
||||
optional<SourceFunction<float>> result = conversion::convertJSON<SourceFunction<float>>(doc, error);
|
||||
if (!result) {
|
||||
state.SkipWithError(error.message.c_str());
|
||||
}
|
||||
@@ -49,7 +42,7 @@ static void Evaluate_SourceFunction(benchmark::State& state) {
|
||||
size_t stopCount = state.range(0);
|
||||
auto doc = createFunctionJSON(stopCount);
|
||||
conversion::Error error;
|
||||
optional<SourceFunction<float>> function = conversion::convert<SourceFunction<float>, JSValue>(doc, error);
|
||||
optional<SourceFunction<float>> function = conversion::convertJSON<SourceFunction<float>>(doc, error);
|
||||
if (!function) {
|
||||
state.SkipWithError(error.message.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user