forked from bblanchon/ArduinoJson
Don't call shrinkToFit()
for deserializeXxx(JsonVariant)
This commit is contained in:
@ -43,10 +43,8 @@ TEST_CASE("deserializeJson(JsonVariant)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("hello")),
|
||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -70,10 +68,8 @@ TEST_CASE("deserializeJson(ElementProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("hello")),
|
||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -82,10 +78,7 @@ TEST_CASE("deserializeJson(ElementProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
Reallocate(sizeofPool(), sizeofArray(2) + sizeofArray(1)),
|
||||
});
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,10 +93,8 @@ TEST_CASE("deserializeJson(MemberProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("world")),
|
||||
Reallocate(sizeofPool(), sizeofObject(1) + sizeofArray(1)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -112,9 +103,6 @@ TEST_CASE("deserializeJson(MemberProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(1)),
|
||||
});
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
}
|
||||
|
@ -43,10 +43,8 @@ TEST_CASE("deserializeMsgPack(JsonVariant)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("hello")),
|
||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -70,10 +68,8 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("hello")),
|
||||
Reallocate(sizeofPool(), sizeofArray(1) + sizeofArray(1)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -82,10 +78,7 @@ TEST_CASE("deserializeMsgPack(ElementProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "[\"hello\",[42]]");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
Reallocate(sizeofPool(), sizeofArray(2) + sizeofArray(1)),
|
||||
});
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,7 +95,6 @@ TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":[42]}");
|
||||
REQUIRE(spy.log() == AllocatorLog{
|
||||
Deallocate(sizeofString("world")),
|
||||
Reallocate(sizeofPool(), sizeofObject(2)),
|
||||
});
|
||||
}
|
||||
|
||||
@ -111,9 +103,6 @@ TEST_CASE("deserializeMsgPack(MemberProxy)") {
|
||||
|
||||
REQUIRE(err == DeserializationError::Ok);
|
||||
REQUIRE(doc.as<std::string>() == "{\"hello\":\"world\",\"value\":[42]}");
|
||||
REQUIRE(spy.log() ==
|
||||
AllocatorLog{
|
||||
Reallocate(sizeofPool(), sizeofObject(2) + sizeofArray(1)),
|
||||
});
|
||||
REQUIRE(spy.log() == AllocatorLog{});
|
||||
}
|
||||
}
|
||||
|
@ -34,6 +34,17 @@ struct is_deserialize_destination<
|
||||
ResourceManager*>::value>::type> : true_type {
|
||||
};
|
||||
|
||||
template <typename TDestination>
|
||||
inline void shrinkJsonDocument(TDestination&) {
|
||||
// no-op by default
|
||||
}
|
||||
|
||||
#if ARDUINOJSON_AUTO_SHRINK
|
||||
inline void shrinkJsonDocument(JsonDocument& doc) {
|
||||
doc.shrinkToFit();
|
||||
}
|
||||
#endif
|
||||
|
||||
template <template <typename> class TDeserializer, typename TDestination,
|
||||
typename TReader, typename TOptions>
|
||||
DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
||||
@ -45,9 +56,7 @@ DeserializationError doDeserialize(TDestination&& dst, TReader reader,
|
||||
dst.clear();
|
||||
auto err = TDeserializer<TReader>(resources, reader)
|
||||
.parse(*data, options.filter, options.nestingLimit);
|
||||
#if ARDUINOJSON_AUTO_SHRINK
|
||||
resources->shrinkToFit();
|
||||
#endif
|
||||
shrinkJsonDocument(dst);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user