From cdbea07317b41dd76a512fbc5d3ef25e1e7d4284 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 11 Apr 2023 15:26:28 +0200 Subject: [PATCH] Reduce scope for variables (sonar). --- src/dag/loaders.cpp | 6 +----- src/mc/api/strategy/WaitStrategy.hpp | 5 ++--- src/sthread/ObjectAccess.cpp | 5 ++--- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/dag/loaders.cpp b/src/dag/loaders.cpp index d4d99a2e71..465e0afb2b 100644 --- a/src/dag/loaders.cpp +++ b/src/dag/loaders.cpp @@ -129,12 +129,8 @@ std::vector create_DAG_from_json(const std::string& filename) } dag.push_back(current); - for (auto const& parent: task["parents"]) { - auto it = successors.find(parent); - if (it == successors.end()) - successors[parent] = {}; + for (auto const& parent : task["parents"]) successors[parent].push_back(current); - } } // Assign successors for (auto const& [parent, successors_list] : successors) diff --git a/src/mc/api/strategy/WaitStrategy.hpp b/src/mc/api/strategy/WaitStrategy.hpp index 39a78c79e5..ae549129f4 100644 --- a/src/mc/api/strategy/WaitStrategy.hpp +++ b/src/mc/api/strategy/WaitStrategy.hpp @@ -58,9 +58,8 @@ public: void consider_best() override { - const auto& [aid, _] = this->next_transition(); - auto actor = actors_to_run_.find(aid); - if (actor != actors_to_run_.end()) { + aid_t aid = next_transition().first; + if (auto actor = actors_to_run_.find(aid); actor != actors_to_run_.end()) { actor->second.mark_todo(); return; } diff --git a/src/sthread/ObjectAccess.cpp b/src/sthread/ObjectAccess.cpp index 6584c7f0bf..6e38668af8 100644 --- a/src/sthread/ObjectAccess.cpp +++ b/src/sthread/ObjectAccess.cpp @@ -66,11 +66,10 @@ static ObjectOwner* get_owner(void* object) { if (owners.empty()) std::atexit(clean_owners); - auto it = owners.find(object); - if (it != owners.end()) + if (auto it = owners.find(object); it != owners.end()) return it->second; auto* o = new ObjectOwner(nullptr); - owners.insert({object, o}); + owners.emplace(object, o); return o; } -- 2.20.1