From 8a9db6cd1e51d0d9323cdfd37f71a4f94483b456 Mon Sep 17 00:00:00 2001 From: Nikolai Tillmann Date: Wed, 13 Sep 2023 10:33:06 -0700 Subject: [PATCH] Avoid some string copies Summary: This is a behavior-preserving change. Reviewed By: wsanville Differential Revision: D49210587 fbshipit-source-id: 7d1d8ce235feff0d80375635299a51f4db471199 --- libredex/DexClass.cpp | 2 +- libredex/RedexContext.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libredex/DexClass.cpp b/libredex/DexClass.cpp index 5e3455c85c7..b33244d5688 100644 --- a/libredex/DexClass.cpp +++ b/libredex/DexClass.cpp @@ -110,7 +110,7 @@ std::string get_simple_deobf_name(const T* ref) { const auto& full_name = ref->get_deobfuscated_name_or_empty(); if (full_name.empty()) { // This comes up for redex-created methods/fields. - return std::string(ref->c_str()); + return ref->str_copy(); } auto dot_pos = full_name.find('.'); auto colon_pos = full_name.find(':'); diff --git a/libredex/RedexContext.cpp b/libredex/RedexContext.cpp index 966e91cf815..5b9537c782e 100644 --- a/libredex/RedexContext.cpp +++ b/libredex/RedexContext.cpp @@ -515,7 +515,7 @@ void RedexContext::mutate_field(DexFieldRef* field, if (rename_on_collision && s_field_map.find(r) != s_field_map.end()) { uint32_t i = 0; while (true) { - r.name = DexString::make_string(("f$" + std::to_string(i++)).c_str()); + r.name = DexString::make_string("f$" + std::to_string(i++)); if (s_field_map.find(r) == s_field_map.end()) { break; } @@ -680,7 +680,7 @@ void RedexContext::mutate_method(DexMethodRef* method, prefix = r.name->str() + "$"; } do { - r.name = DexString::make_string((prefix + std::to_string(i++)).c_str()); + r.name = DexString::make_string(prefix + std::to_string(i++)); } while (s_method_map.count(r)); } else { // We are about to change its class. Use a better name to remember its