ART: Fix performance-inefficient-vector-operation
Bug: 32619234
Test: m test-art-host
Change-Id: I286e27424ac39c0fed308811dc3004e734c0560c
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index 12a8354..437bf36 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -115,6 +115,7 @@
static std::string CommandLine() {
std::vector<std::string> command;
+ command.reserve(original_argc);
for (int i = 0; i < original_argc; ++i) {
command.push_back(original_argv[i]);
}
diff --git a/dexoptanalyzer/dexoptanalyzer.cc b/dexoptanalyzer/dexoptanalyzer.cc
index 21cdcf1..2b97fb4 100644
--- a/dexoptanalyzer/dexoptanalyzer.cc
+++ b/dexoptanalyzer/dexoptanalyzer.cc
@@ -52,6 +52,7 @@
static std::string CommandLine() {
std::vector<std::string> command;
+ command.reserve(original_argc);
for (int i = 0; i < original_argc; ++i) {
command.push_back(original_argv[i]);
}
diff --git a/profman/profman.cc b/profman/profman.cc
index 734cdf4..2935a05 100644
--- a/profman/profman.cc
+++ b/profman/profman.cc
@@ -60,6 +60,7 @@
static std::string CommandLine() {
std::vector<std::string> command;
+ command.reserve(original_argc);
for (int i = 0; i < original_argc; ++i) {
command.push_back(original_argv[i]);
}
diff --git a/runtime/oat_file_manager.cc b/runtime/oat_file_manager.cc
index 7ac1ab4..2c882ec 100644
--- a/runtime/oat_file_manager.cc
+++ b/runtime/oat_file_manager.cc
@@ -118,9 +118,10 @@
}
std::vector<const OatFile*> OatFileManager::GetBootOatFiles() const {
- std::vector<const OatFile*> oat_files;
std::vector<gc::space::ImageSpace*> image_spaces =
Runtime::Current()->GetHeap()->GetBootImageSpaces();
+ std::vector<const OatFile*> oat_files;
+ oat_files.reserve(image_spaces.size());
for (gc::space::ImageSpace* image_space : image_spaces) {
oat_files.push_back(image_space->GetOatFile());
}
@@ -153,6 +154,7 @@
std::vector<const OatFile*> OatFileManager::RegisterImageOatFiles(
const std::vector<gc::space::ImageSpace*>& spaces) {
std::vector<const OatFile*> oat_files;
+ oat_files.reserve(spaces.size());
for (gc::space::ImageSpace* space : spaces) {
oat_files.push_back(RegisterOatFile(space->ReleaseOatFile()));
}
@@ -290,10 +292,12 @@
// Generate type index information for each dex file.
std::vector<TypeIndexInfo> loaded_types;
+ loaded_types.reserve(dex_files_loaded.size());
for (const DexFile* dex_file : dex_files_loaded) {
loaded_types.push_back(TypeIndexInfo(dex_file));
}
std::vector<TypeIndexInfo> unloaded_types;
+ unloaded_types.reserve(dex_files_unloaded.size());
for (const DexFile* dex_file : dex_files_unloaded) {
unloaded_types.push_back(TypeIndexInfo(dex_file));
}
diff --git a/tools/hiddenapi/hiddenapi.cc b/tools/hiddenapi/hiddenapi.cc
index 65a4945..2f016e9 100644
--- a/tools/hiddenapi/hiddenapi.cc
+++ b/tools/hiddenapi/hiddenapi.cc
@@ -39,6 +39,7 @@
static std::string CommandLine() {
std::vector<std::string> command;
+ command.reserve(original_argc);
for (int i = 0; i < original_argc; ++i) {
command.push_back(original_argv[i]);
}