Topology::remove: simplify loop
Do not remove the empty vector if there are no more elements.
There is a small amount of port types so removing that map entry would
not make a significant difference.
Not removing it however simplifies the code.
Tested: Topology Unit Tests Pass
Change-Id: Ica8e09ee9a056adf3f50d1c1afd243898ead0acf
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index 90d8c8d..5ae4d94 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -99,41 +99,23 @@
boardNames.erase(boardFind);
- for (auto it = upstreamPorts.begin(); it != upstreamPorts.end();)
+ for (auto& upstreamPort : upstreamPorts)
{
- auto pathIt =
- std::find(it->second.begin(), it->second.end(), boardPath);
- if (pathIt != it->second.end())
+ auto pathIt = std::find(upstreamPort.second.begin(),
+ upstreamPort.second.end(), boardPath);
+ if (pathIt != upstreamPort.second.end())
{
- it->second.erase(pathIt);
- }
-
- if (it->second.empty())
- {
- it = upstreamPorts.erase(it);
- }
- else
- {
- ++it;
+ upstreamPort.second.erase(pathIt);
}
}
- for (auto it = downstreamPorts.begin(); it != downstreamPorts.end();)
+ for (auto& downstreamPort : downstreamPorts)
{
- auto pathIt =
- std::find(it->second.begin(), it->second.end(), boardPath);
- if (pathIt != it->second.end())
+ auto pathIt = std::find(downstreamPort.second.begin(),
+ downstreamPort.second.end(), boardPath);
+ if (pathIt != downstreamPort.second.end())
{
- it->second.erase(pathIt);
- }
-
- if (it->second.empty())
- {
- it = downstreamPorts.erase(it);
- }
- else
- {
- ++it;
+ downstreamPort.second.erase(pathIt);
}
}
}