diff --git a/include/nt_Value.h b/include/nt_Value.h index 074bb8d538..0b5a1b16d5 100644 --- a/include/nt_Value.h +++ b/include/nt_Value.h @@ -91,7 +91,8 @@ class Value { val->m_val.data.v_string.len = val->m_string.size(); return val; } - static std::shared_ptr MakeString(std::string&& value) { + template + static std::shared_ptr MakeString(T&& value) { auto val = std::make_shared(NT_STRING, private_init()); val->m_string = std::move(value); val->m_val.data.v_string.str = const_cast(val->m_string.c_str()); @@ -105,7 +106,8 @@ class Value { val->m_val.data.v_raw.len = val->m_string.size(); return val; } - static std::shared_ptr MakeRaw(std::string&& value) { + template + static std::shared_ptr MakeRaw(T&& value) { auto val = std::make_shared(NT_RAW, private_init()); val->m_string = std::move(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); @@ -119,7 +121,8 @@ class Value { val->m_val.data.v_raw.len = val->m_string.size(); return val; } - static std::shared_ptr MakeRpc(std::string&& value) { + template + static std::shared_ptr MakeRpc(T&& value) { auto val = std::make_shared(NT_RPC, private_init()); val->m_string = std::move(value); val->m_val.data.v_raw.str = const_cast(val->m_string.c_str()); diff --git a/test/unit/StorageTest.cpp b/test/unit/StorageTest.cpp index 29c9818c5d..002a5eeb52 100644 --- a/test/unit/StorageTest.cpp +++ b/test/unit/StorageTest.cpp @@ -51,13 +51,12 @@ class StorageTestPersistent : public StorageTest { storage.SetEntryTypeValue("double/neg", Value::MakeDouble(-1.5)); storage.SetEntryTypeValue("double/zero", Value::MakeDouble(0.0)); storage.SetEntryTypeValue("double/big", Value::MakeDouble(1.3e8)); - storage.SetEntryTypeValue("string/empty", Value::MakeString(StringRef(""))); - storage.SetEntryTypeValue("string/normal", - Value::MakeString(StringRef("hello"))); + storage.SetEntryTypeValue("string/empty", Value::MakeString("")); + storage.SetEntryTypeValue("string/normal", Value::MakeString("hello")); storage.SetEntryTypeValue("string/special", Value::MakeString(StringRef("\0\3\5\n", 4))); - storage.SetEntryTypeValue("raw/empty", Value::MakeRaw(StringRef(""))); - storage.SetEntryTypeValue("raw/normal", Value::MakeRaw(StringRef("hello"))); + storage.SetEntryTypeValue("raw/empty", Value::MakeRaw("")); + storage.SetEntryTypeValue("raw/normal", Value::MakeRaw("hello")); storage.SetEntryTypeValue("raw/special", Value::MakeRaw(StringRef("\0\3\5\n", 4))); storage.SetEntryTypeValue("booleanarr/empty", @@ -578,15 +577,14 @@ TEST_F(StorageTest, LoadPersistent) { EXPECT_EQ(*Value::MakeDouble(-1.5), *storage.GetEntryValue("double/neg")); EXPECT_EQ(*Value::MakeDouble(0.0), *storage.GetEntryValue("double/zero")); EXPECT_EQ(*Value::MakeDouble(1.3e8), *storage.GetEntryValue("double/big")); - EXPECT_EQ(*Value::MakeString(StringRef("")), - *storage.GetEntryValue("string/empty")); - EXPECT_EQ(*Value::MakeString(StringRef("hello")), + EXPECT_EQ(*Value::MakeString(""), *storage.GetEntryValue("string/empty")); + EXPECT_EQ(*Value::MakeString("hello"), *storage.GetEntryValue("string/normal")); EXPECT_EQ(*Value::MakeString(StringRef("\0\3\5\n", 4)), *storage.GetEntryValue("string/special")); - EXPECT_EQ(*Value::MakeRaw(StringRef("")), + EXPECT_EQ(*Value::MakeRaw(""), *storage.GetEntryValue("raw/empty")); - EXPECT_EQ(*Value::MakeRaw(StringRef("hello")), + EXPECT_EQ(*Value::MakeRaw("hello"), *storage.GetEntryValue("raw/normal")); EXPECT_EQ(*Value::MakeRaw(StringRef("\0\3\5\n", 4)), *storage.GetEntryValue("raw/special")); diff --git a/test/unit/ValueTest.cpp b/test/unit/ValueTest.cpp index 03ed61695d..e477e8ea8d 100644 --- a/test/unit/ValueTest.cpp +++ b/test/unit/ValueTest.cpp @@ -62,7 +62,7 @@ TEST_F(ValueTest, Double) { } TEST_F(ValueTest, String) { - auto v = Value::MakeString(llvm::StringRef("hello")); + auto v = Value::MakeString("hello"); ASSERT_EQ(NT_STRING, v->type()); ASSERT_EQ("hello", v->GetString()); NT_Value cv; @@ -72,7 +72,7 @@ TEST_F(ValueTest, String) { ASSERT_EQ(llvm::StringRef("hello"), cv.data.v_string.str); ASSERT_EQ(5u, cv.data.v_string.len); - v = Value::MakeString(llvm::StringRef("goodbye")); + v = Value::MakeString("goodbye"); ASSERT_EQ(NT_STRING, v->type()); ASSERT_EQ("goodbye", v->GetString()); ConvertToC(*v, &cv); @@ -84,7 +84,7 @@ TEST_F(ValueTest, String) { } TEST_F(ValueTest, Raw) { - auto v = Value::MakeRaw(llvm::StringRef("hello")); + auto v = Value::MakeRaw("hello"); ASSERT_EQ(NT_RAW, v->type()); ASSERT_EQ("hello", v->GetRaw()); NT_Value cv; @@ -94,7 +94,7 @@ TEST_F(ValueTest, Raw) { ASSERT_EQ(llvm::StringRef("hello"), cv.data.v_string.str); ASSERT_EQ(5u, cv.data.v_string.len); - v = Value::MakeRaw(llvm::StringRef("goodbye")); + v = Value::MakeRaw("goodbye"); ASSERT_EQ(NT_RAW, v->type()); ASSERT_EQ("goodbye", v->GetRaw()); ConvertToC(*v, &cv); @@ -282,12 +282,12 @@ TEST_F(ValueTest, DoubleComparison) { } TEST_F(ValueTest, StringComparison) { - auto v1 = Value::MakeString(llvm::StringRef("hello")); - auto v2 = Value::MakeString(llvm::StringRef("hello")); + auto v1 = Value::MakeString("hello"); + auto v2 = Value::MakeString("hello"); ASSERT_EQ(*v1, *v2); - v2 = Value::MakeString(llvm::StringRef("world")); // different contents + v2 = Value::MakeString("world"); // different contents ASSERT_NE(*v1, *v2); - v2 = Value::MakeString(llvm::StringRef("goodbye")); // different size + v2 = Value::MakeString("goodbye"); // different size ASSERT_NE(*v1, *v2); }