From e6d1e3afe2e55ebcb96c26ef9868a0d82c92a423 Mon Sep 17 00:00:00 2001 From: SangBin Cho Date: Thu, 30 Jul 2020 10:34:24 -0700 Subject: [PATCH] Use pass by reference for const auto in for loop. (#9811) --- src/ray/common/task/scheduling_resources.cc | 2 +- src/ray/gcs/test/redis_actor_info_accessor_test.cc | 2 +- src/ray/raylet/node_manager.cc | 4 ++-- .../raylet/scheduling/cluster_resource_scheduler.cc | 12 ++++++------ src/ray/stats/stats_test.cc | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/ray/common/task/scheduling_resources.cc b/src/ray/common/task/scheduling_resources.cc index 4ef60da27..49f75176c 100644 --- a/src/ray/common/task/scheduling_resources.cc +++ b/src/ray/common/task/scheduling_resources.cc @@ -305,7 +305,7 @@ const std::string ResourceSet::ToString() const { const std::unordered_map ResourceSet::GetResourceMap() const { std::unordered_map result; - for (const auto resource_pair : resource_capacity_) { + for (const auto &resource_pair : resource_capacity_) { result[resource_pair.first] = resource_pair.second.ToDouble(); } return result; diff --git a/src/ray/gcs/test/redis_actor_info_accessor_test.cc b/src/ray/gcs/test/redis_actor_info_accessor_test.cc index 605ca75ba..b7f91740e 100644 --- a/src/ray/gcs/test/redis_actor_info_accessor_test.cc +++ b/src/ray/gcs/test/redis_actor_info_accessor_test.cc @@ -45,7 +45,7 @@ class ActorInfoAccessorTest : public AccessorTestBase { } void GenCheckpointData() { - for (const auto item : id_to_data_) { + for (const auto &item : id_to_data_) { const ActorID &id = item.first; ActorCheckpointList checkpoints; for (size_t i = 0; i < checkpoint_number_; ++i) { diff --git a/src/ray/raylet/node_manager.cc b/src/ray/raylet/node_manager.cc index 4762e67f0..8dc9f6426 100644 --- a/src/ray/raylet/node_manager.cc +++ b/src/ray/raylet/node_manager.cc @@ -3589,7 +3589,7 @@ void NodeManager::FlushObjectsToFree() { void NodeManager::HandleGetNodeStats(const rpc::GetNodeStatsRequest &node_stats_request, rpc::GetNodeStatsReply *reply, rpc::SendReplyCallback send_reply_callback) { - for (const auto task : local_queues_.GetTasks(TaskState::INFEASIBLE)) { + for (const auto &task : local_queues_.GetTasks(TaskState::INFEASIBLE)) { if (task.GetTaskSpecification().IsActorCreationTask()) { auto infeasible_task = reply->add_infeasible_tasks(); infeasible_task->ParseFromString(task.GetTaskSpecification().Serialize()); @@ -3597,7 +3597,7 @@ void NodeManager::HandleGetNodeStats(const rpc::GetNodeStatsRequest &node_stats_ } // Report tasks that are not scheduled because // resources are occupied by other actors/tasks. - for (const auto task : local_queues_.GetTasks(TaskState::READY)) { + for (const auto &task : local_queues_.GetTasks(TaskState::READY)) { if (task.GetTaskSpecification().IsActorCreationTask()) { auto ready_task = reply->add_ready_tasks(); ready_task->ParseFromString(task.GetTaskSpecification().Serialize()); diff --git a/src/ray/raylet/scheduling/cluster_resource_scheduler.cc b/src/ray/raylet/scheduling/cluster_resource_scheduler.cc index 92405e26b..dc7e6df79 100644 --- a/src/ray/raylet/scheduling/cluster_resource_scheduler.cc +++ b/src/ray/raylet/scheduling/cluster_resource_scheduler.cc @@ -329,7 +329,7 @@ TaskResourceInstances NodeResourceInstances::GetAvailableResourceInstances() { task_resources.predefined_resources[i] = this->predefined_resources[i].available; } - for (const auto it : this->custom_resources) { + for (const auto &it : this->custom_resources) { task_resources.custom_resources.emplace(it.first, it.second.available); } @@ -365,8 +365,8 @@ bool TaskResourceInstances::IsEmpty() const { } } - for (const auto custom_resource : custom_resources) { - for (const auto custom_resource_instances : custom_resource.second) { + for (const auto &custom_resource : custom_resources) { + for (const auto &custom_resource_instances : custom_resource.second) { if (custom_resource_instances != 0) { return false; } @@ -526,7 +526,7 @@ int64_t ClusterResourceScheduler::IsSchedulable(const TaskRequest &task_req, } // Now check custom resources. - for (const auto task_req_custom_resource : task_req.custom_resources) { + for (const auto &task_req_custom_resource : task_req.custom_resources) { auto it = resources.custom_resources.find(task_req_custom_resource.id); if (it == resources.custom_resources.end()) { @@ -1038,7 +1038,7 @@ void ClusterResourceScheduler::UpdateLocalAvailableResourcesFromResourceInstance auto it = local_resources_.custom_resources.find(custom_resource.first); if (it != local_resources_.custom_resources.end()) { custom_resource.second.available = 0; - for (const auto available : it->second.available) { + for (const auto &available : it->second.available) { custom_resource.second.available += available; } } @@ -1053,7 +1053,7 @@ void ClusterResourceScheduler::FreeTaskResourceInstances( &local_resources_.predefined_resources[i]); } - for (const auto task_allocation_custom_resource : task_allocation->custom_resources) { + for (const auto &task_allocation_custom_resource : task_allocation->custom_resources) { auto it = local_resources_.custom_resources.find(task_allocation_custom_resource.first); if (it != local_resources_.custom_resources.end()) { diff --git a/src/ray/stats/stats_test.cc b/src/ray/stats/stats_test.cc index 47ed0d68a..01f5dfc50 100644 --- a/src/ray/stats/stats_test.cc +++ b/src/ray/stats/stats_test.cc @@ -43,7 +43,7 @@ class MockExporter : public opencensus::stats::StatsExporter::Handler { ASSERT_EQ("current_worker", descriptor.name()); ASSERT_EQ(opencensus::stats::ViewData::Type::kDouble, view_data.type()); - for (const auto row : view_data.double_data()) { + for (const auto &row : view_data.double_data()) { for (size_t i = 0; i < descriptor.columns().size(); ++i) { if (descriptor.columns()[i].name() == "WorkerPidKey") { ASSERT_EQ("1000", row.first[i]);