Merge "libutil: no special copy from StaticString16" am: 7d067aee62 am: ece939ecc9 am: b8e683537f am: 73fcfd0c52
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1751786
Change-Id: I5cc9831a8a940cdead57b4a0811e55eec34092ef
diff --git a/libutils/String16_test.cpp b/libutils/String16_test.cpp
index ea4e049..c6e6f74 100644
--- a/libutils/String16_test.cpp
+++ b/libutils/String16_test.cpp
@@ -58,6 +58,14 @@
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 @@
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 @@
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 53f11fd..3ef56a3 100644
--- a/libutils/include/utils/String16.h
+++ b/libutils/include/utils/String16.h
@@ -174,16 +174,6 @@
template <size_t N>
explicit constexpr String16(const StaticData<N>& s) : mString(s.data) {}
-
-public:
- template <size_t N>
- explicit constexpr String16(const StaticString16<N>& s) : mString(s.mString) {}
- template <size_t N>
- constexpr String16& operator=(const StaticString16<N>& s) {
- release();
- mString = s.mString;
- return *this;
- }
};
// String16 can be trivially moved using memcpy() because moving does not