From 0b2acdfcc99ecf3ff36fc6337e14b171170f38cf Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 2 Oct 2015 18:25:19 -0700 Subject: [PATCH] Use const auto& in for loops. Change-Id: Ic437c59797ee4e7dc38291da35c72d827bc89c8d --- tests/gtest_main.cpp | 4 ++-- tests/pthread_test.cpp | 10 +++++----- tests/unistd_test.cpp | 7 +++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp index dd2dece07..b79c8aafb 100644 --- a/tests/gtest_main.cpp +++ b/tests/gtest_main.cpp @@ -635,7 +635,7 @@ static void HandleSignals(std::vector& testcase_list, sigquit_flag = false; // Print current running tests. printf("List of current running tests:\n"); - for (auto& child_proc : child_proc_list) { + for (const auto& child_proc : child_proc_list) { if (child_proc.pid != 0) { std::string test_name = testcase_list[child_proc.testcase_id].GetTestName(child_proc.test_id); int64_t current_time_ns = NanoTime(); @@ -646,7 +646,7 @@ static void HandleSignals(std::vector& testcase_list, } else if (sigint_flag) { sigint_flag = false; // Kill current running tests. - for (auto& child_proc : child_proc_list) { + for (const auto& child_proc : child_proc_list) { if (child_proc.pid != 0) { // Send SIGKILL to ensure the child process can be killed unconditionally. kill(child_proc.pid, SIGKILL); diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp index 176676268..9f887e3b7 100644 --- a/tests/pthread_test.cpp +++ b/tests/pthread_test.cpp @@ -70,7 +70,7 @@ TEST(pthread, pthread_key_many_distinct) { std::vector keys; auto scope_guard = make_scope_guard([&keys]{ - for (auto key : keys) { + for (const auto& key : keys) { EXPECT_EQ(0, pthread_key_delete(key)); } }); @@ -108,7 +108,7 @@ TEST(pthread, pthread_key_not_exceed_PTHREAD_KEYS_MAX) { } // Don't leak keys. - for (auto key : keys) { + for (const auto& key : keys) { EXPECT_EQ(0, pthread_key_delete(key)); } keys.clear(); @@ -1162,7 +1162,7 @@ TEST(pthread, pthread_attr_getstack__main_thread) { void* maps_stack_hi = NULL; std::vector maps; ASSERT_TRUE(Maps::parse_maps(&maps)); - for (auto& map : maps) { + for (const auto& map : maps) { if (map.pathname == "[stack]") { maps_stack_hi = reinterpret_cast(map.addr_end); break; @@ -1552,8 +1552,8 @@ class StrictAlignmentAllocator { } ~StrictAlignmentAllocator() { - for (auto& p : allocated_array) { - delete [] p; + for (const auto& p : allocated_array) { + delete[] p; } } diff --git a/tests/unistd_test.cpp b/tests/unistd_test.cpp index 500377c52..0a97abc44 100644 --- a/tests/unistd_test.cpp +++ b/tests/unistd_test.cpp @@ -832,11 +832,10 @@ TEST(unistd, get_cpu_count_from_string) { } TEST(unistd, sysconf_SC_NPROCESSORS_ONLN) { - std::string s; - ASSERT_TRUE(android::base::ReadFileToString("/sys/devices/system/cpu/online", &s)); - std::vector strs = android::base::Split(s, ","); + std::string line; + ASSERT_TRUE(android::base::ReadFileToString("/sys/devices/system/cpu/online", &line)); long online_cpus = 0; - for (auto& s : strs) { + for (const std::string& s : android::base::Split(line, ",")) { std::vector numbers = android::base::Split(s, "-"); if (numbers.size() == 1u) { online_cpus++; -- 2.11.0