Skip to content

Commit 080fced

Browse files
julianbrostAl2Klimov
authored andcommitted
Simplify DependencyGraph:RemoveDependency() method
1 parent c6725c8 commit 080fced

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

lib/base/dependencygraph.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,14 @@ void DependencyGraph::RemoveDependency(ConfigObject* child, ConfigObject* parent
2020
std::unique_lock<std::mutex> lock(m_Mutex);
2121

2222
if (auto it(m_Dependencies.find(Edge(parent, child))); it != m_Dependencies.end()) {
23-
// A number <= 1 means, this isn't referenced by anyone and should be erased from the container.
24-
if (it->count == 1) {
23+
if (it->count > 1) {
24+
// Remove a duplicate edge from child to node, i.e. decrement the corresponding counter.
25+
m_Dependencies.modify(it, [](Edge& e) { e.count--; });
26+
} else {
27+
// Remove the last edge from child to node (decrementing the counter would set it to 0),
28+
// thus remove that connection from the data structure completely.
2529
m_Dependencies.erase(it);
26-
return;
2730
}
28-
29-
// Otherwise, each remove operation will should decrement this by 1 till it reaches <= 1
30-
// and causes the edge to completely be erased from the container.
31-
m_Dependencies.modify(it, [](Edge& e) { e.count--; });
3231
}
3332
}
3433

0 commit comments

Comments
 (0)