From 39e8b63746dcf925532ff361b487980d42fa1abb Mon Sep 17 00:00:00 2001 From: Benoit Blanchon Date: Mon, 3 Jul 2023 12:02:24 +0200 Subject: [PATCH] Remove `shallowCopy()` --- CHANGELOG.md | 1 + extras/tests/JsonDocument/ElementProxy.cpp | 8 -- extras/tests/JsonDocument/MemberProxy.cpp | 8 -- extras/tests/JsonVariant/CMakeLists.txt | 1 - extras/tests/JsonVariant/isnull.cpp | 13 ---- extras/tests/JsonVariant/shallowCopy.cpp | 87 ---------------------- src/ArduinoJson/Variant/VariantRefBase.hpp | 12 --- 7 files changed, 1 insertion(+), 129 deletions(-) delete mode 100644 extras/tests/JsonVariant/shallowCopy.cpp diff --git a/CHANGELOG.md b/CHANGELOG.md index 6020dcdc..818acabb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,3 +18,4 @@ HEAD * Fix double lookup in `to()` * Fix double call to `size()` in `serializeMsgPack()` * Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name +* Remove `JsonVariant::shallowCopy()` diff --git a/extras/tests/JsonDocument/ElementProxy.cpp b/extras/tests/JsonDocument/ElementProxy.cpp index 6cf981bc..484fc845 100644 --- a/extras/tests/JsonDocument/ElementProxy.cpp +++ b/extras/tests/JsonDocument/ElementProxy.cpp @@ -246,11 +246,3 @@ TEST_CASE("ElementProxy cast to JsonVariant") { CHECK(doc.as() == "[\"toto\"]"); } - -TEST_CASE("ElementProxy::shallowCopy()") { - JsonDocument doc1(1024), doc2(1024); - doc2["hello"] = "world"; - doc1[0].shallowCopy(doc2); - - CHECK(doc1.as() == "[{\"hello\":\"world\"}]"); -} diff --git a/extras/tests/JsonDocument/MemberProxy.cpp b/extras/tests/JsonDocument/MemberProxy.cpp index e6a48a39..f1956b54 100644 --- a/extras/tests/JsonDocument/MemberProxy.cpp +++ b/extras/tests/JsonDocument/MemberProxy.cpp @@ -328,14 +328,6 @@ TEST_CASE("MemberProxy::createNestedObject(key)") { CHECK(doc["status"]["weather"]["temp"] == 42); } -TEST_CASE("MemberProxy::shallowCopy()") { - JsonDocument doc1(1024), doc2(1024); - doc2["hello"] = "world"; - doc1["obj"].shallowCopy(doc2); - - CHECK(doc1.as() == "{\"obj\":{\"hello\":\"world\"}}"); -} - TEST_CASE("Deduplicate keys") { JsonDocument doc(1024); diff --git a/extras/tests/JsonVariant/CMakeLists.txt b/extras/tests/JsonVariant/CMakeLists.txt index d43a971c..bbdf17ba 100644 --- a/extras/tests/JsonVariant/CMakeLists.txt +++ b/extras/tests/JsonVariant/CMakeLists.txt @@ -21,7 +21,6 @@ add_executable(JsonVariantTests overflow.cpp remove.cpp set.cpp - shallowCopy.cpp size.cpp stl_containers.cpp subscript.cpp diff --git a/extras/tests/JsonVariant/isnull.cpp b/extras/tests/JsonVariant/isnull.cpp index c05535a0..20c17e3f 100644 --- a/extras/tests/JsonVariant/isnull.cpp +++ b/extras/tests/JsonVariant/isnull.cpp @@ -70,19 +70,6 @@ TEST_CASE("JsonVariant::isNull()") { REQUIRE(variant.isNull() == true); } - SECTION("returns true for a shallow null copy") { - JsonDocument doc2(128); - variant.shallowCopy(doc2); - CHECK(variant.isNull() == true); - } - - SECTION("returns false for a shallow array copy") { - JsonDocument doc2(128); - doc2[0] = 42; - variant.shallowCopy(doc2); - CHECK(variant.isNull() == false); - } - SECTION("works with JsonVariantConst") { variant.set(42); diff --git a/extras/tests/JsonVariant/shallowCopy.cpp b/extras/tests/JsonVariant/shallowCopy.cpp deleted file mode 100644 index a45ecf39..00000000 --- a/extras/tests/JsonVariant/shallowCopy.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// ArduinoJson - https://arduinojson.org -// Copyright © 2014-2023, Benoit BLANCHON -// MIT License - -#include -#include - -TEST_CASE("JsonVariant::shallowCopy()") { - JsonDocument doc1(1024), doc2(1024); - JsonVariant variant = doc1.to(); - - SECTION("JsonVariant::shallowCopy(JsonDocument&)") { - doc2["hello"] = "world"; - - variant.shallowCopy(doc2); - - CHECK(variant.as() == "{\"hello\":\"world\"}"); - - // altering the linked document should change the result - doc2["hello"] = "WORLD!"; - - CHECK(variant.as() == "{\"hello\":\"WORLD!\"}"); - } - - SECTION("JsonVariant::shallowCopy(MemberProxy)") { - doc2["obj"]["hello"] = "world"; - - variant.shallowCopy(doc2["obj"]); - - CHECK(variant.as() == "{\"hello\":\"world\"}"); - - // altering the linked document should change the result - doc2["obj"]["hello"] = "WORLD!"; - - CHECK(variant.as() == "{\"hello\":\"WORLD!\"}"); - } - - SECTION("JsonVariant::shallowCopy(ElementProxy)") { - doc2[0]["hello"] = "world"; - - variant.shallowCopy(doc2[0]); - - CHECK(variant.as() == "{\"hello\":\"world\"}"); - - // altering the linked document should change the result - doc2[0]["hello"] = "WORLD!"; - - CHECK(variant.as() == "{\"hello\":\"WORLD!\"}"); - } - - SECTION("target is unbound") { - JsonVariant unbound; - variant["hello"] = "world"; - - variant.shallowCopy(unbound); - - CHECK(variant.isUnbound() == false); - CHECK(variant.isNull() == true); - CHECK(variant.memoryUsage() == 0); - CHECK(variant.size() == 0); - } - - SECTION("variant is unbound") { - JsonVariant unbound; - doc2["hello"] = "world"; - - unbound.shallowCopy(doc2); - - CHECK(unbound.isUnbound() == true); - CHECK(unbound.isNull() == true); - CHECK(unbound.memoryUsage() == 0); - CHECK(unbound.size() == 0); - } - - SECTION("preserves owned key bit") { - doc2.set(42); - - doc1["a"].shallowCopy(doc2); - doc1[std::string("b")].shallowCopy(doc2); - - JsonObject::iterator it = doc1.as().begin(); - - CHECK(it->key().isLinked() == true); - ++it; - CHECK(it->key().isLinked() == false); - } -} diff --git a/src/ArduinoJson/Variant/VariantRefBase.hpp b/src/ArduinoJson/Variant/VariantRefBase.hpp index 37d76f48..dbc8d52e 100644 --- a/src/ArduinoJson/Variant/VariantRefBase.hpp +++ b/src/ArduinoJson/Variant/VariantRefBase.hpp @@ -106,18 +106,6 @@ class VariantRefBase : public VariantTag { return Converter::checkJson(getVariantConst()); } - // Shallow copies the specified value. - // https://arduinojson.org/v6/api/jsonvariant/shallowcopy/ - FORCE_INLINE void shallowCopy(ArduinoJson::JsonVariantConst target) { - VariantData* data = getOrCreateData(); - if (!data) - return; - data->setNull(getResourceManager()); - const VariantData* targetData = VariantAttorney::getData(target); - if (targetData) - *data = *targetData; - } - // Copies the specified value. // https://arduinojson.org/v6/api/jsonvariant/set/ template