Fix performance-for-range-copy warnings
Bug: 30413223
Test: make with WITH_TIDY=1 DEFAULT_GLOBAL_TIDY_CHECKS=-*,performance*
Change-Id: I3ad102f2b0f971266d57488a3bd57d312f7ee3e6
diff --git a/adb/daemon/shell_service.cpp b/adb/daemon/shell_service.cpp
index 01097ac..8805fc1 100644
--- a/adb/daemon/shell_service.cpp
+++ b/adb/daemon/shell_service.cpp
@@ -273,7 +273,7 @@
}
std::vector<std::string> joined_env;
- for (auto it : env) {
+ for (const auto& it : env) {
const char* key = it.first.c_str();
const char* value = it.second.c_str();
joined_env.push_back(android::base::StringPrintf("%s=%s", key, value));
diff --git a/fastboot/fuzzy_fastboot/main.cpp b/fastboot/fuzzy_fastboot/main.cpp
index 479a06a..ef34771 100644
--- a/fastboot/fuzzy_fastboot/main.cpp
+++ b/fastboot/fuzzy_fastboot/main.cpp
@@ -281,7 +281,7 @@
std::vector<std::string> vars;
EXPECT_EQ(fb->GetVarAll(&vars), SUCCESS) << "getvar:all failed";
EXPECT_GT(vars.size(), 0) << "getvar:all did not respond with any INFO responses";
- for (const auto s : vars) {
+ for (const auto& s : vars) {
EXPECT_LE(s.size(), FB_RESPONSE_SZ - 4)
<< "getvar:all included an INFO response: 'INFO" + s << "' which is too long";
}
@@ -316,7 +316,7 @@
EXPECT_GT(parts.size(), 0)
<< "getvar:all did not report any partition-size: through INFO responses";
std::set<std::string> allowed{"ext4", "f2fs", "raw"};
- for (const auto p : parts) {
+ for (const auto& p : parts) {
EXPECT_GE(std::get<1>(p), 0);
std::string part(std::get<0>(p));
std::set<std::string> allowed{"ext4", "f2fs", "raw"};
@@ -355,7 +355,7 @@
if (num_slots > 0) {
EXPECT_EQ(fb->GetVar("current-slot", &var), SUCCESS) << "getvar:current-slot failed";
- for (const auto p : parts) {
+ for (const auto& p : parts) {
std::string part(std::get<0>(p));
std::regex reg("([[:graph:]]*)_([[:lower:]])");
std::smatch sm;
@@ -378,7 +378,7 @@
}
}
// Ensure each partition has the correct slot suffix
- for (const auto iter : part_slots) {
+ for (const auto& iter : part_slots) {
const std::set<char>& char_set = iter.second;
std::string chars;
for (char c : char_set) {
@@ -572,7 +572,7 @@
std::vector<std::tuple<std::string, uint64_t>> parts;
EXPECT_EQ(fb->Partitions(&parts), SUCCESS) << "getvar:all failed in locked mode";
std::string resp;
- for (const auto tup : parts) {
+ for (const auto& tup : parts) {
EXPECT_EQ(fb->Flash(std::get<0>(tup), &resp), DEVICE_FAIL)
<< "Device did not respond with FAIL when trying to flash '" << std::get<0>(tup)
<< "' in locked mode";
@@ -585,7 +585,7 @@
std::vector<std::tuple<std::string, uint64_t>> parts;
EXPECT_EQ(fb->Partitions(&parts), SUCCESS) << "getvar:all failed";
std::string resp;
- for (const auto tup : parts) {
+ for (const auto& tup : parts) {
EXPECT_EQ(fb->Erase(std::get<0>(tup), &resp), DEVICE_FAIL)
<< "Device did not respond with FAIL when trying to erase '" << std::get<0>(tup)
<< "' in locked mode";
@@ -601,7 +601,7 @@
EXPECT_EQ(fb->GetVar("slot-count", &resp), SUCCESS) << "getvar:slot-count failed";
int32_t num_slots = strtol(resp.c_str(), nullptr, 10);
- for (const auto tup : parts) {
+ for (const auto& tup : parts) {
std::string part(std::get<0>(tup));
std::regex reg("([[:graph:]]*)_([[:lower:]])");
std::smatch sm;
@@ -1554,12 +1554,12 @@
void GenerateXmlTests(const extension::Configuration& config) {
// Build the getvar tests
- for (const auto it : config.getvars) {
+ for (const auto& it : config.getvars) {
GETVAR_XML_TESTS.push_back(std::make_pair(it.first, it.second));
}
// Build the partition tests, to interface with gtest we need to do it this way
- for (const auto it : config.partitions) {
+ for (const auto& it : config.partitions) {
const auto tup = std::make_tuple(it.first, it.second);
PARTITION_XML_TESTS.push_back(tup); // All partitions
@@ -1581,7 +1581,7 @@
// Build the packed tests, only useful if we have a hash
if (!config.checksum.empty()) {
- for (const auto it : config.packed) {
+ for (const auto& it : config.packed) {
for (const auto& test : it.second.tests) {
const auto tup = std::make_tuple(it.first, test);
if (test.expect == extension::OKAY) { // only testing the success case
@@ -1608,7 +1608,7 @@
}
// Build oem tests
- for (const auto it : config.oem) {
+ for (const auto& it : config.oem) {
auto oem_cmd = it.second;
for (const auto& t : oem_cmd.tests) {
OEM_XML_TESTS.push_back(std::make_tuple(it.first, oem_cmd.restricted, t));
diff --git a/fs_mgr/fs_mgr_overlayfs.cpp b/fs_mgr/fs_mgr_overlayfs.cpp
index d2d8dc1..54196a1 100644
--- a/fs_mgr/fs_mgr_overlayfs.cpp
+++ b/fs_mgr/fs_mgr_overlayfs.cpp
@@ -521,7 +521,7 @@
// hijack __mount() report format to help triage
auto report = "__mount(source=overlay,target="s + mount_point + ",type=overlay";
const auto opt_list = android::base::Split(options, ",");
- for (const auto opt : opt_list) {
+ for (const auto& opt : opt_list) {
if (android::base::StartsWith(opt, kUpperdirOption)) {
report = report + "," + opt;
break;
diff --git a/libunwindstack/DwarfCfa.cpp b/libunwindstack/DwarfCfa.cpp
index 0fa1638..4ba8a4b 100644
--- a/libunwindstack/DwarfCfa.cpp
+++ b/libunwindstack/DwarfCfa.cpp
@@ -260,7 +260,7 @@
}
// Log any of the expression data.
- for (const auto line : expression_lines) {
+ for (const auto& line : expression_lines) {
log(indent + 1, "%s", line.c_str());
}
return true;
diff --git a/libunwindstack/tools/unwind_for_offline.cpp b/libunwindstack/tools/unwind_for_offline.cpp
index 640992f..c8a8ab5 100644
--- a/libunwindstack/tools/unwind_for_offline.cpp
+++ b/libunwindstack/tools/unwind_for_offline.cpp
@@ -224,7 +224,7 @@
sp_map_start = map_info->start;
}
- for (auto frame : unwinder.frames()) {
+ for (const auto& frame : unwinder.frames()) {
map_info = maps.Find(frame.sp);
if (map_info != nullptr && sp_map_start != map_info->start) {
stacks.emplace_back(std::make_pair(frame.sp, map_info->end));
diff --git a/llkd/libllkd.cpp b/llkd/libllkd.cpp
index 427dace..969f26b 100644
--- a/llkd/libllkd.cpp
+++ b/llkd/libllkd.cpp
@@ -610,7 +610,7 @@
std::string llkFormat(const std::unordered_set<std::string>& blacklist) {
std::string ret;
- for (auto entry : blacklist) {
+ for (const auto& entry : blacklist) {
if (ret.size()) {
ret += ",";
}