topology: fix nesting in fillAssocForPortId
Refactor the branches in that function to return early on failure
instead of nesting if statements.
Tested: Inspection only.
Change-Id: I6a7cd1275c1b3deda537c34feb13c8ea7bf448cb
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index a5037f0..d2f7f33 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -91,17 +91,21 @@
std::unordered_map<std::string, std::set<Association>>& result,
BoardPathsView boardPaths, const Path& upstream, const Path& downstream)
{
- if (boardTypes[upstream] == "Chassis" || boardTypes[upstream] == "Board")
+ if (boardTypes[upstream] != "Chassis" && boardTypes[upstream] != "Board")
{
- // The downstream path must be one we care about.
- if (std::ranges::contains(boardPaths, downstream))
- {
- result[downstream].insert({"contained_by", "containing", upstream});
- if (powerPaths.contains(downstream))
- {
- result[downstream].insert({"powering", "powered_by", upstream});
- }
- }
+ return;
+ }
+ // The downstream path must be one we care about.
+ if (!std::ranges::contains(boardPaths, downstream))
+ {
+ return;
+ }
+
+ result[downstream].insert({"contained_by", "containing", upstream});
+
+ if (powerPaths.contains(downstream))
+ {
+ result[downstream].insert({"powering", "powered_by", upstream});
}
}