diff options
| -rw-r--r-- | libdexfile/external/dex_file_supp_test.cc | 8 | ||||
| -rw-r--r-- | libdexfile/external/include/art_api/dex_file_support.h | 12 |
2 files changed, 12 insertions, 8 deletions
diff --git a/libdexfile/external/dex_file_supp_test.cc b/libdexfile/external/dex_file_supp_test.cc index 3dd08c0d01..2f7ad5080f 100644 --- a/libdexfile/external/dex_file_supp_test.cc +++ b/libdexfile/external/dex_file_supp_test.cc @@ -75,6 +75,12 @@ TEST(DexStringTest, move_assign) { EXPECT_EQ(std::string_view(s2), "foo"); } +TEST(DexStringTest, reassign) { + auto s = DexString("foo"); + s = DexString("bar"); + EXPECT_EQ(std::string_view(s), "bar"); +} + TEST(DexStringTest, data_access) { auto s = DexString("foo"); EXPECT_STREQ(s.data(), "foo"); @@ -272,7 +278,7 @@ TEST(DexFileTest, move_construct) { std::unique_ptr<DexFile> dex_file = GetTestDexData(); ASSERT_NE(dex_file, nullptr); - auto df1 = DexFile(std::move(*dex_file.release())); + auto df1 = DexFile(std::move(*dex_file)); auto df2 = DexFile(std::move(df1)); MethodInfo info = df2.GetMethodInfoForOffset(0x100, false); diff --git a/libdexfile/external/include/art_api/dex_file_support.h b/libdexfile/external/include/art_api/dex_file_support.h index ddd9143edc..24222af4dc 100644 --- a/libdexfile/external/include/art_api/dex_file_support.h +++ b/libdexfile/external/include/art_api/dex_file_support.h @@ -23,6 +23,7 @@ #include <memory> #include <string> #include <string_view> +#include <utility> #include <vector> #include <android-base/macros.h> @@ -35,7 +36,9 @@ namespace dex { // Minimal std::string look-alike for a string returned from libdexfile. class DexString final { public: - DexString(DexString&& dex_str) noexcept { ReplaceExtString(std::move(dex_str)); } + DexString(DexString&& dex_str) noexcept : ext_string_(dex_str.ext_string_) { + dex_str.ext_string_ = ExtDexFileMakeString("", 0); + } explicit DexString(const char* str = "") : ext_string_(ExtDexFileMakeString(str, std::strlen(str))) {} explicit DexString(std::string_view str) @@ -43,7 +46,7 @@ class DexString final { ~DexString() { ExtDexFileFreeString(ext_string_); } DexString& operator=(DexString&& dex_str) noexcept { - ReplaceExtString(std::move(dex_str)); + std::swap(ext_string_, dex_str.ext_string_); return *this; } @@ -72,11 +75,6 @@ class DexString final { explicit DexString(const ExtDexFileString* ext_string) : ext_string_(ext_string) {} const ExtDexFileString* ext_string_; // Owned instance. Never nullptr. - void ReplaceExtString(DexString&& dex_str) { - ext_string_ = dex_str.ext_string_; - dex_str.ext_string_ = ExtDexFileMakeString("", 0); - } - DISALLOW_COPY_AND_ASSIGN(DexString); }; |