Avoid going through char* for std::string API
Bug: 13186058
(cherry picked from commit 14ae4a873e91ae8cb1c00013579b5b058268879d)
Change-Id: Ib529cc10abc2d413e9da65c043dbc2638b734acd
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 6897f8a..1c721c9 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -545,11 +545,8 @@
const char* oat_cache_filename,
std::string* error_msg) {
Locks::mutator_lock_->AssertNotHeld(Thread::Current()); // Avoid starving GC.
- std::string dex2oat_string(GetAndroidRoot());
- dex2oat_string += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
- const char* dex2oat = dex2oat_string.c_str();
-
- const char* class_path = Runtime::Current()->GetClassPathString().c_str();
+ std::string dex2oat(GetAndroidRoot());
+ dex2oat += (kIsDebugBuild ? "/bin/dex2oatd" : "/bin/dex2oat");
gc::Heap* heap = Runtime::Current()->GetHeap();
std::string boot_image_option("--boot-image=");
@@ -573,7 +570,7 @@
argv.push_back("--runtime-arg");
argv.push_back("-classpath");
argv.push_back("--runtime-arg");
- argv.push_back(class_path);
+ argv.push_back(Runtime::Current()->GetClassPathString());
if (!kIsTargetBuild) {
argv.push_back("--host");
}
diff --git a/runtime/utils.cc b/runtime/utils.cc
index 8e6ddaf..39a051c 100644
--- a/runtime/utils.cc
+++ b/runtime/utils.cc
@@ -1212,10 +1212,11 @@
// Convert the args to char pointers.
const char* program = arg_vector[0].c_str();
std::vector<char*> args;
- for (std::vector<std::string>::const_iterator it = arg_vector.begin(); it != arg_vector.end();
- ++it) {
- CHECK(*it != nullptr);
- args.push_back(const_cast<char*>(it->c_str()));
+ for (size_t i = 0; i < arg_vector.size(); ++i) {
+ const std::string& arg = arg_vector[i];
+ char* arg_str = const_cast<char*>(arg.c_str());
+ CHECK(arg_str != nullptr) << i;
+ args.push_back(arg_str);
}
args.push_back(NULL);