ART: Fix inefficent find/rfind
Use character instead of string versions where possible.
Bug: 32619234
Test: m test-art-host
Change-Id: Ifa0a68f17cf9fac5a8c15a6a1f1d085f0c8dcdd7
diff --git a/dexlayout/dexlayout_test.cc b/dexlayout/dexlayout_test.cc
index f3b4c86..1658967 100644
--- a/dexlayout/dexlayout_test.cc
+++ b/dexlayout/dexlayout_test.cc
@@ -292,7 +292,7 @@
if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
return false;
}
- size_t dex_file_last_slash = dex_file.rfind("/");
+ size_t dex_file_last_slash = dex_file.rfind('/');
std::string dex_file_name = dex_file.substr(dex_file_last_slash + 1);
std::vector<std::string> unzip_exec_argv =
{ "/usr/bin/unzip", dex_file, "classes.dex", "-d", tmp_dir};
@@ -381,7 +381,7 @@
bool DexFileLayoutExec(std::string* error_msg) {
ScratchFile tmp_file;
std::string tmp_name = tmp_file.GetFilename();
- size_t tmp_last_slash = tmp_name.rfind("/");
+ size_t tmp_last_slash = tmp_name.rfind('/');
std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
// Write inputs and expected outputs.
@@ -416,7 +416,7 @@
bool DexFileLayoutFixedPointExec(std::string* error_msg) {
ScratchFile tmp_file;
std::string tmp_name = tmp_file.GetFilename();
- size_t tmp_last_slash = tmp_name.rfind("/");
+ size_t tmp_last_slash = tmp_name.rfind('/');
std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
// Unzip the test dex file to the classes.dex destination. It is required to unzip since
@@ -482,7 +482,7 @@
bool UnreferencedCatchHandlerExec(std::string* error_msg, const char* filename) {
ScratchFile tmp_file;
std::string tmp_name = tmp_file.GetFilename();
- size_t tmp_last_slash = tmp_name.rfind("/");
+ size_t tmp_last_slash = tmp_name.rfind('/');
std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
// Write inputs and expected outputs.
diff --git a/runtime/runtime_callbacks_test.cc b/runtime/runtime_callbacks_test.cc
index 983278d..a4d6c3d 100644
--- a/runtime/runtime_callbacks_test.cc
+++ b/runtime/runtime_callbacks_test.cc
@@ -261,7 +261,7 @@
std::string location(initial_dex_file.GetLocation());
std::string event =
std::string("PreDefine:") + descriptor + " <" +
- location.substr(location.rfind("/") + 1, location.size()) + ">";
+ location.substr(location.rfind('/') + 1, location.size()) + ">";
data.push_back(event);
}
diff --git a/test/ti-agent/common_helper.cc b/test/ti-agent/common_helper.cc
index e57a493..f5e1e1b 100644
--- a/test/ti-agent/common_helper.cc
+++ b/test/ti-agent/common_helper.cc
@@ -107,7 +107,7 @@
return nullptr;
}
std::string type(fsig);
- type = type.substr(type.find(")") + 1);
+ type = type.substr(type.find(')') + 1);
jvmtienv->Deallocate(reinterpret_cast<unsigned char*>(fsig));
jvmtienv->Deallocate(reinterpret_cast<unsigned char*>(fname));
jvmtienv->Deallocate(reinterpret_cast<unsigned char*>(fgen));
diff --git a/test/ti-stress/stress.cc b/test/ti-stress/stress.cc
index 06d5af0..5d7c2f3 100644
--- a/test/ti-stress/stress.cc
+++ b/test/ti-stress/stress.cc
@@ -533,7 +533,7 @@
return;
}
std::string type(method_info.GetSignature());
- type = type.substr(type.find(")") + 1);
+ type = type.substr(type.find(')') + 1);
std::string out_val(was_popped_by_exception ? "" : GetValOf(jvmtienv, env, type, val));
LOG(INFO) << "Leaving method \"" << method_info << "\". Thread is \"" << info.GetName() << "\"."
<< std::endl