Loading libutils/String16.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,12 @@ String16::String16(const String16& o) acquire(); } String16::String16(String16&& o) noexcept : mString(o.mString) { o.mString = getEmptyString(); } String16::String16(const String16& o, size_t len, size_t begin) : mString(getEmptyString()) { Loading Loading @@ -126,6 +132,13 @@ String16::~String16() release(); } String16& String16::operator=(String16&& other) noexcept { release(); mString = other.mString; other.mString = getEmptyString(); return *this; } size_t String16::size() const { if (isStaticString()) { Loading libutils/String16_test.cpp +19 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,13 @@ TEST(String16Test, Move) { EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, MoveAssign) { String16 tmp("Verify me"); String16 another; another = std::move(tmp); EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, Size) { String16 tmp("Verify me"); EXPECT_EQ(9U, tmp.size()); Loading Loading @@ -123,6 +130,10 @@ 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) { Loading Loading @@ -174,10 +185,16 @@ TEST(String16Test, StringSetToStaticString) { EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, StringMoveFromStaticString) { TEST(String16Test, StringMoveAssignFromStaticString) { StaticString16 tmp(u"Verify me"); String16 another(std::move(tmp)); 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) { Loading libutils/include/utils/String16.h +8 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ class String16 public: String16(); String16(const String16& o); String16(String16&& o) noexcept; String16(const String16& o, size_t len, size_t begin=0); Loading Loading @@ -69,6 +70,7 @@ public: status_t append(const char16_t* other, size_t len); inline String16& operator=(const String16& other); String16& operator=(String16&& other) noexcept; inline String16& operator+=(const String16& other); inline String16 operator+(const String16& other) const; Loading Loading @@ -176,6 +178,12 @@ protected: 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 Loading Loading
libutils/String16.cpp +13 −0 Original line number Diff line number Diff line Loading @@ -96,6 +96,12 @@ String16::String16(const String16& o) acquire(); } String16::String16(String16&& o) noexcept : mString(o.mString) { o.mString = getEmptyString(); } String16::String16(const String16& o, size_t len, size_t begin) : mString(getEmptyString()) { Loading Loading @@ -126,6 +132,13 @@ String16::~String16() release(); } String16& String16::operator=(String16&& other) noexcept { release(); mString = other.mString; other.mString = getEmptyString(); return *this; } size_t String16::size() const { if (isStaticString()) { Loading
libutils/String16_test.cpp +19 −2 Original line number Diff line number Diff line Loading @@ -64,6 +64,13 @@ TEST(String16Test, Move) { EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, MoveAssign) { String16 tmp("Verify me"); String16 another; another = std::move(tmp); EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, Size) { String16 tmp("Verify me"); EXPECT_EQ(9U, tmp.size()); Loading Loading @@ -123,6 +130,10 @@ 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) { Loading Loading @@ -174,10 +185,16 @@ TEST(String16Test, StringSetToStaticString) { EXPECT_STR16EQ(u"Verify me", another); } TEST(String16Test, StringMoveFromStaticString) { TEST(String16Test, StringMoveAssignFromStaticString) { StaticString16 tmp(u"Verify me"); String16 another(std::move(tmp)); 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) { Loading
libutils/include/utils/String16.h +8 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ class String16 public: String16(); String16(const String16& o); String16(String16&& o) noexcept; String16(const String16& o, size_t len, size_t begin=0); Loading Loading @@ -69,6 +70,7 @@ public: status_t append(const char16_t* other, size_t len); inline String16& operator=(const String16& other); String16& operator=(String16&& other) noexcept; inline String16& operator+=(const String16& other); inline String16 operator+(const String16& other) const; Loading Loading @@ -176,6 +178,12 @@ protected: 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 Loading