Ver código fonte

Remove `shallowCopy()`

Benoit Blanchon 2 anos atrás
pai
commit
39e8b63746

+ 1 - 0
CHANGELOG.md

@@ -18,3 +18,4 @@ HEAD
 * Fix double lookup in `to<JsonVariant>()`
 * Fix double call to `size()` in `serializeMsgPack()`
 * Include `ARDUINOJSON_SLOT_OFFSET_SIZE` in the namespace name
+* Remove `JsonVariant::shallowCopy()` 

+ 0 - 8
extras/tests/JsonDocument/ElementProxy.cpp

@@ -246,11 +246,3 @@ TEST_CASE("ElementProxy cast to JsonVariant") {
 
   CHECK(doc.as<std::string>() == "[\"toto\"]");
 }
-
-TEST_CASE("ElementProxy::shallowCopy()") {
-  JsonDocument doc1(1024), doc2(1024);
-  doc2["hello"] = "world";
-  doc1[0].shallowCopy(doc2);
-
-  CHECK(doc1.as<std::string>() == "[{\"hello\":\"world\"}]");
-}

+ 0 - 8
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<std::string>() == "{\"obj\":{\"hello\":\"world\"}}");
-}
-
 TEST_CASE("Deduplicate keys") {
   JsonDocument doc(1024);
 

+ 0 - 1
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

+ 0 - 13
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);
 

+ 0 - 87
extras/tests/JsonVariant/shallowCopy.cpp

@@ -1,87 +0,0 @@
-// ArduinoJson - https://arduinojson.org
-// Copyright © 2014-2023, Benoit BLANCHON
-// MIT License
-
-#include <ArduinoJson.h>
-#include <catch.hpp>
-
-TEST_CASE("JsonVariant::shallowCopy()") {
-  JsonDocument doc1(1024), doc2(1024);
-  JsonVariant variant = doc1.to<JsonVariant>();
-
-  SECTION("JsonVariant::shallowCopy(JsonDocument&)") {
-    doc2["hello"] = "world";
-
-    variant.shallowCopy(doc2);
-
-    CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
-
-    // altering the linked document should change the result
-    doc2["hello"] = "WORLD!";
-
-    CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
-  }
-
-  SECTION("JsonVariant::shallowCopy(MemberProxy)") {
-    doc2["obj"]["hello"] = "world";
-
-    variant.shallowCopy(doc2["obj"]);
-
-    CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
-
-    // altering the linked document should change the result
-    doc2["obj"]["hello"] = "WORLD!";
-
-    CHECK(variant.as<std::string>() == "{\"hello\":\"WORLD!\"}");
-  }
-
-  SECTION("JsonVariant::shallowCopy(ElementProxy)") {
-    doc2[0]["hello"] = "world";
-
-    variant.shallowCopy(doc2[0]);
-
-    CHECK(variant.as<std::string>() == "{\"hello\":\"world\"}");
-
-    // altering the linked document should change the result
-    doc2[0]["hello"] = "WORLD!";
-
-    CHECK(variant.as<std::string>() == "{\"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<JsonObject>().begin();
-
-    CHECK(it->key().isLinked() == true);
-    ++it;
-    CHECK(it->key().isLinked() == false);
-  }
-}

+ 0 - 12
src/ArduinoJson/Variant/VariantRefBase.hpp

@@ -106,18 +106,6 @@ class VariantRefBase : public VariantTag {
     return Converter<T>::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 <typename T>