Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use pass by reference for const auto in for loop. (#9811)
  • Loading branch information
rkooo567 committed Jul 30, 2020
1 parent 0c3b9eb commit e6d1e3a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ray/common/task/scheduling_resources.cc
Expand Up @@ -305,7 +305,7 @@ const std::string ResourceSet::ToString() const {

const std::unordered_map<std::string, double> ResourceSet::GetResourceMap() const {
std::unordered_map<std::string, double> 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;
Expand Down
2 changes: 1 addition & 1 deletion src/ray/gcs/test/redis_actor_info_accessor_test.cc
Expand Up @@ -45,7 +45,7 @@ class ActorInfoAccessorTest : public AccessorTestBase<ActorID, ActorTableData> {
}

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) {
Expand Down
4 changes: 2 additions & 2 deletions src/ray/raylet/node_manager.cc
Expand Up @@ -3589,15 +3589,15 @@ 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());
}
}
// 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());
Expand Down
12 changes: 6 additions & 6 deletions src/ray/raylet/scheduling/cluster_resource_scheduler.cc
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/ray/stats/stats_test.cc
Expand Up @@ -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]);
Expand Down

0 comments on commit e6d1e3a

Please sign in to comment.