From 6f92640d4521e0765aac65c654e3fc6ecf2072b1 Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Wed, 30 Jun 2021 09:04:29 +0900 Subject: [PATCH] libutil: no special copy from StaticString16 String16's ctors already handle static strings, so we don't need a specialized constructor which accepts StaticString16. Bug: n/a Test: libutils_test Change-Id: I93a1ba70d743ff9c73f113d53ffba73cef6adade --- libutils/String16_test.cpp | 26 ++++++++++++++++++-------- libutils/include/utils/String16.h | 10 ---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libutils/String16_test.cpp b/libutils/String16_test.cpp index 917f1a3e6..7d7230ef9 100644 --- a/libutils/String16_test.cpp +++ b/libutils/String16_test.cpp @@ -58,6 +58,14 @@ TEST(String16Test, Copy) { EXPECT_STR16EQ(u"Verify me", another); } +TEST(String16Test, CopyAssign) { + String16 tmp("Verify me"); + String16 another; + another = tmp; + EXPECT_STR16EQ(u"Verify me", tmp); + EXPECT_STR16EQ(u"Verify me", another); +} + TEST(String16Test, Move) { String16 tmp("Verify me"); String16 another(std::move(tmp)); @@ -130,10 +138,6 @@ TEST(String16Test, StaticStringMove) { String16 another(std::move(tmp)); EXPECT_STR16EQ(u"Verify me", another); EXPECT_TRUE(another.isStaticString()); - // move/copy from StaticString16 is specialized (just copy the handle). - // no extra actions required. - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_TRUE(tmp.isStaticString()); } TEST(String16Test, StaticStringSize) { @@ -185,16 +189,22 @@ TEST(String16Test, StringSetToStaticString) { EXPECT_STR16EQ(u"Verify me", another); } +TEST(String16Test, StringCopyAssignFromStaticString) { + StaticString16 tmp(u"Verify me"); + String16 another(u"nonstatic"); + another = tmp; + EXPECT_STR16EQ(u"Verify me", another); + EXPECT_TRUE(another.isStaticString()); + EXPECT_STR16EQ(u"Verify me", tmp); + EXPECT_TRUE(tmp.isStaticString()); +} + TEST(String16Test, StringMoveAssignFromStaticString) { StaticString16 tmp(u"Verify me"); String16 another(u"nonstatic"); another = std::move(tmp); EXPECT_STR16EQ(u"Verify me", another); EXPECT_TRUE(another.isStaticString()); - // move/copy from StaticString16 is specialized (just copy handle). - // no extra actions required. - EXPECT_STR16EQ(u"Verify me", tmp); - EXPECT_TRUE(tmp.isStaticString()); } TEST(String16Test, EmptyStringIsStatic) { diff --git a/libutils/include/utils/String16.h b/libutils/include/utils/String16.h index 53f11fd72..3ef56a3cf 100644 --- a/libutils/include/utils/String16.h +++ b/libutils/include/utils/String16.h @@ -174,16 +174,6 @@ protected: template explicit constexpr String16(const StaticData& s) : mString(s.data) {} - -public: - template - explicit constexpr String16(const StaticString16& s) : mString(s.mString) {} - template - constexpr String16& operator=(const StaticString16& s) { - release(); - mString = s.mString; - return *this; - } }; // String16 can be trivially moved using memcpy() because moving does not