Skip to content

Commit

Permalink
clang-tidy: modernize-loop-convert (envoyproxy#7790)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Argueta <dereka@pinterest.com>
  • Loading branch information
derekargueta authored and mattklein123 committed Aug 3, 2019
1 parent 662eccc commit 2ca5b26
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 58 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ WarningsAsErrors: 'abseil-duration-*,
bugprone-use-after-move,
clang-analyzer-core.DivideZero,
modernize-deprecated-headers,
modernize-loop-convert,
modernize-make-shared,
modernize-make-unique,
modernize-return-braced-init-list,
Expand Down
4 changes: 2 additions & 2 deletions source/common/grpc/google_grpc_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ Buffer::InstancePtr GoogleGrpcUtils::makeBufferInstance(const grpc::ByteBuffer&
return nullptr;
}

for (size_t i = 0; i < slices.size(); i++) {
buffer->addBufferFragment(*new GrpcSliceBufferFragmentImpl(std::move(slices[i])));
for (auto& slice : slices) {
buffer->addBufferFragment(*new GrpcSliceBufferFragmentImpl(std::move(slice)));
}
return buffer;
}
Expand Down
6 changes: 3 additions & 3 deletions source/common/http/codec_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ class StreamCallbackHelper {
// removed multiple times.
// The vector may not be safely resized without making sure the run.*Callbacks() helper
// functions above still handle removeCallbacks_() calls mid-loop.
for (size_t i = 0; i < callbacks_.size(); i++) {
if (callbacks_[i] == &callbacks) {
callbacks_[i] = nullptr;
for (auto& callback : callbacks_) {
if (callback == &callbacks) {
callback = nullptr;
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/common/http/codes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ CodeStatsImpl::CodeStatsImpl(Stats::SymbolTable& symbol_table)
vcluster_(stat_name_pool_.add("vcluster")), vhost_(stat_name_pool_.add("vhost")),
zone_(stat_name_pool_.add("zone")) {

for (uint32_t i = 0; i < NumHttpCodes; ++i) {
rc_stat_names_[i] = nullptr;
for (auto& rc_stat_name : rc_stat_names_) {
rc_stat_name = nullptr;
}

// Pre-allocate response codes 200, 404, and 503, as those seem quite likely.
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/filters/common/rbac/engine_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ bool RoleBasedAccessControlEngineImpl::allowed(const Network::Connection& connec
std::string* effective_policy_id) const {
bool matched = false;

for (auto it = policies_.begin(); it != policies_.end(); it++) {
if (it->second.matches(connection, headers, metadata)) {
for (const auto& policy : policies_) {
if (policy.second.matches(connection, headers, metadata)) {
matched = true;
if (effective_policy_id != nullptr) {
*effective_policy_id = it->first;
*effective_policy_id = policy.first;
}
break;
}
Expand Down
8 changes: 4 additions & 4 deletions source/extensions/filters/network/mysql_proxy/mysql_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ void MySQLFilter::onCommand(Command& command) {
}
hsql::TableAccessMap table_access_map;
result.getStatement(i)->tablesAccessed(table_access_map);
for (auto it = table_access_map.begin(); it != table_access_map.end(); ++it) {
auto& operations = *fields[it->first].mutable_list_value();
for (auto ot = it->second.begin(); ot != it->second.end(); ++ot) {
operations.add_values()->set_string_value(*ot);
for (auto& it : table_access_map) {
auto& operations = *fields[it.first].mutable_list_value();
for (const auto& ot : it.second) {
operations.add_values()->set_string_value(ot);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void InstanceImpl::ThreadLocalPool::onClusterAddOrUpdateNonVirtual(
});

ASSERT(host_address_map_.empty());
for (uint32_t i = 0; i < cluster_->prioritySet().hostSetsPerPriority().size(); i++) {
for (auto& host : cluster_->prioritySet().hostSetsPerPriority()[i]->hosts()) {
for (const auto& i : cluster_->prioritySet().hostSetsPerPriority()) {
for (auto& host : i->hosts()) {
host_address_map_[host->address()->asString()] = host;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ bool PreviousPrioritiesRetryPriority::adjustForAttemptedPriorities(
// This allows us to fall back to the unmodified priority load when we run out of priorities
// instead of failing to route requests.
if (total_availability == 0) {
for (size_t i = 0; i < excluded_priorities_.size(); ++i) {
excluded_priorities_[i] = false;
for (auto&& excluded_priority : excluded_priorities_) {
excluded_priority = false;
}
attempted_priorities_.clear();
total_availability =
Expand Down
5 changes: 2 additions & 3 deletions source/extensions/stat_sinks/hystrix/hystrix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ void ClusterStatsCache::printToStream(std::stringstream& out_str) {
void ClusterStatsCache::printRollingWindow(absl::string_view name, RollingWindow rolling_window,
std::stringstream& out_str) {
out_str << name << " | ";
for (auto specific_stat_vec_itr = rolling_window.begin();
specific_stat_vec_itr != rolling_window.end(); ++specific_stat_vec_itr) {
out_str << *specific_stat_vec_itr << " | ";
for (uint64_t& specific_stat_vec_itr : rolling_window) {
out_str << specific_stat_vec_itr << " | ";
}
out_str << std::endl;
}
Expand Down
12 changes: 6 additions & 6 deletions source/extensions/tracers/zipkin/zipkin_core_types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ Span::Span(const Span& span) : time_source_(span.time_source_) {
}

void Span::setServiceName(const std::string& service_name) {
for (auto it = annotations_.begin(); it != annotations_.end(); it++) {
it->changeEndpointServiceName(service_name);
for (auto& annotation : annotations_) {
annotation.changeEndpointServiceName(service_name);
}
}

Expand Down Expand Up @@ -203,15 +203,15 @@ const std::string Span::toJson() {

std::vector<std::string> annotation_json_vector;

for (auto it = annotations_.begin(); it != annotations_.end(); it++) {
annotation_json_vector.push_back(it->toJson());
for (auto& annotation : annotations_) {
annotation_json_vector.push_back(annotation.toJson());
}
Util::addArrayToJson(json_string, annotation_json_vector,
ZipkinJsonFieldNames::get().SPAN_ANNOTATIONS);

std::vector<std::string> binary_annotation_json_vector;
for (auto it = binary_annotations_.begin(); it != binary_annotations_.end(); it++) {
binary_annotation_json_vector.push_back(it->toJson());
for (auto& binary_annotation : binary_annotations_) {
binary_annotation_json_vector.push_back(binary_annotation.toJson());
}
Util::addArrayToJson(json_string, binary_annotation_json_vector,
ZipkinJsonFieldNames::get().SPAN_BINARY_ANNOTATIONS);
Expand Down
4 changes: 2 additions & 2 deletions source/server/http/admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -672,8 +672,8 @@ Http::Code AdminImpl::handlerLogging(absl::string_view url, Http::HeaderMap&,
response.add("usage: /logging?<name>=<level> (change single level)\n");
response.add("usage: /logging?level=<level> (change all levels)\n");
response.add("levels: ");
for (size_t i = 0; i < ARRAY_SIZE(spdlog::level::level_string_views); i++) {
response.add(fmt::format("{} ", spdlog::level::level_string_views[i]));
for (auto level_string_view : spdlog::level::level_string_views) {
response.add(fmt::format("{} ", level_string_view));
}

response.add("\n");
Expand Down
4 changes: 2 additions & 2 deletions source/server/options_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ OptionsImpl::OptionsImpl(int argc, const char* const* argv,
spdlog::level::level_enum default_log_level)
: signal_handling_enabled_(true) {
std::string log_levels_string = "Log levels: ";
for (size_t i = 0; i < ARRAY_SIZE(spdlog::level::level_string_views); i++) {
log_levels_string += fmt::format("[{}]", spdlog::level::level_string_views[i]);
for (auto level_string_view : spdlog::level::level_string_views) {
log_levels_string += fmt::format("[{}]", level_string_view);
}
log_levels_string +=
fmt::format("\nDefault is [{}]", spdlog::level::level_string_views[default_log_level]);
Expand Down
4 changes: 2 additions & 2 deletions test/common/network/lc_trie_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class LcTrieTest : public testing::Test {
for (size_t i = 0; i < cidr_range_strings.size(); i++) {
std::pair<std::string, std::vector<Address::CidrRange>> ip_tags;
ip_tags.first = fmt::format("tag_{0}", i);
for (size_t j = 0; j < cidr_range_strings[i].size(); j++) {
ip_tags.second.push_back(Address::CidrRange::create(cidr_range_strings[i][j]));
for (const auto& j : cidr_range_strings[i]) {
ip_tags.second.push_back(Address::CidrRange::create(j));
}
output.push_back(ip_tags);
}
Expand Down
4 changes: 2 additions & 2 deletions test/common/tcp/conn_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ class ConnPoolImplForTest : public ConnPoolImpl {

protected:
void onConnReleased(ConnPoolImpl::ActiveConn& conn) override {
for (auto i = test_conns_.begin(); i != test_conns_.end(); i++) {
if (conn.conn_.get() == i->connection_) {
for (auto& test_conn : test_conns_) {
if (conn.conn_.get() == test_conn.connection_) {
onConnReleasedForTest();
break;
}
Expand Down
4 changes: 2 additions & 2 deletions test/common/upstream/outlier_detection_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class OutlierDetectorImplTest : public testing::Test {
}

template <typename T> void loadRq(HostVector& hosts, int num_rq, T code) {
for (uint64_t i = 0; i < hosts.size(); i++) {
loadRq(hosts[i], num_rq, code);
for (auto& host : hosts) {
loadRq(host, num_rq, code);
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/common/upstream/upstream_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,10 +400,10 @@ TEST_F(StrictDnsClusterImplTest, HostRemovalActiveHealthSkipped) {
const auto& hosts = cluster.prioritySet().hostSetsPerPriority()[0]->hosts();
EXPECT_EQ(2UL, hosts.size());

for (size_t i = 0; i < hosts.size(); ++i) {
EXPECT_TRUE(hosts[i]->healthFlagGet(Host::HealthFlag::FAILED_ACTIVE_HC));
hosts[i]->healthFlagClear(Host::HealthFlag::FAILED_ACTIVE_HC);
hosts[i]->healthFlagClear(Host::HealthFlag::PENDING_ACTIVE_HC);
for (const auto& host : hosts) {
EXPECT_TRUE(host->healthFlagGet(Host::HealthFlag::FAILED_ACTIVE_HC));
host->healthFlagClear(Host::HealthFlag::FAILED_ACTIVE_HC);
host->healthFlagClear(Host::HealthFlag::PENDING_ACTIVE_HC);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ std::string makeBulkStringArray(std::vector<std::string>&& command_strings) {
std::stringstream result;

result << "*" << command_strings.size() << "\r\n";
for (uint64_t i = 0; i < command_strings.size(); i++) {
result << "$" << command_strings[i].size() << "\r\n";
result << command_strings[i] << "\r\n";
for (auto& command_string : command_strings) {
result << "$" << command_string.size() << "\r\n";
result << command_string << "\r\n";
}

return result.str();
Expand Down
8 changes: 4 additions & 4 deletions test/extensions/filters/http/jwt_authn/group_verifier_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class GroupVerifierTest : public testing::Test {
std::unordered_map<std::string, AuthenticatorCallback>
createAsyncMockAuthsAndVerifier(const std::vector<std::string>& providers) {
std::unordered_map<std::string, AuthenticatorCallback> callbacks;
for (std::size_t i = 0; i < providers.size(); ++i) {
for (const auto& provider : providers) {
auto mock_auth = std::make_unique<MockAuthenticator>();
EXPECT_CALL(*mock_auth, doVerify(_, _, _, _))
.WillOnce(Invoke(
[&callbacks, iss = providers[i]](Http::HeaderMap&, std::vector<JwtLocationConstPtr>*,
SetPayloadCallback, AuthenticatorCallback callback) {
[&callbacks, iss = provider](Http::HeaderMap&, std::vector<JwtLocationConstPtr>*,
SetPayloadCallback, AuthenticatorCallback callback) {
callbacks[iss] = std::move(callback);
}));
EXPECT_CALL(*mock_auth, onDestroy()).Times(1);
mock_auths_[providers[i]] = std::move(mock_auth);
mock_auths_[provider] = std::move(mock_auth);
}
createVerifier();
return callbacks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,9 @@ std::string makeBulkStringArray(std::vector<std::string>&& command_strings) {
std::stringstream result;

result << "*" << command_strings.size() << "\r\n";
for (uint64_t i = 0; i < command_strings.size(); i++) {
result << "$" << command_strings[i].size() << "\r\n";
result << command_strings[i] << "\r\n";
for (auto& command_string : command_strings) {
result << "$" << command_string.size() << "\r\n";
result << command_string << "\r\n";
}

return result.str();
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fake_upstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,8 @@ FakeUpstream::waitForHttpConnection(Event::Dispatcher& client_dispatcher,
Event::TestTimeSystem& time_system = upstreams[0]->timeSystem();
auto end_time = time_system.monotonicTime() + timeout;
while (time_system.monotonicTime() < end_time) {
for (auto it = upstreams.begin(); it != upstreams.end(); ++it) {
FakeUpstream& upstream = **it;
for (auto& it : upstreams) {
FakeUpstream& upstream = *it;
Thread::ReleasableLockGuard lock(upstream.lock_);
if (upstream.new_connections_.empty()) {
time_system.waitFor(upstream.lock_, upstream.new_connection_event_, 5ms);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/http2_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1182,10 +1182,10 @@ Http2RingHashIntegrationTest::~Http2RingHashIntegrationTest() {
codec_client_->close();
codec_client_ = nullptr;
}
for (auto it = fake_upstream_connections_.begin(); it != fake_upstream_connections_.end(); ++it) {
AssertionResult result = (*it)->close();
for (auto& fake_upstream_connection : fake_upstream_connections_) {
AssertionResult result = fake_upstream_connection->close();
RELEASE_ASSERT(result, result.message());
result = (*it)->waitForDisconnect();
result = fake_upstream_connection->waitForDisconnect();
RELEASE_ASSERT(result, result.message());
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/server/config_validation/server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class ValidationServerTest_1 : public ValidationServerTest {
auto files = TestUtility::listFiles(ValidationServerTest::directory_, false);

// Strip directory part. options_ adds it for each test.
for (std::vector<std::string>::iterator it = files.begin(); it != files.end(); it++) {
(*it) = it->substr(directory_.length() + 1);
for (auto& file : files) {
file = file.substr(directory_.length() + 1);
}
return files;
}
Expand Down

0 comments on commit 2ca5b26

Please sign in to comment.