cmComputeComponentGraph: Move work out of constructor into Compute() method
The computation of Tarjan's algorithm is an expensive operation which should not be done in the constructor. Move this work into a dedicated Compute() method, and call this method explicitly.
This commit is contained in:
parent
7788494257
commit
bd0d03386b
@ -7,6 +7,12 @@
|
|||||||
|
|
||||||
cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
|
cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
|
||||||
: InputGraph(input)
|
: InputGraph(input)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
cmComputeComponentGraph::~cmComputeComponentGraph() = default;
|
||||||
|
|
||||||
|
void cmComputeComponentGraph::Compute()
|
||||||
{
|
{
|
||||||
// Identify components.
|
// Identify components.
|
||||||
this->Tarjan();
|
this->Tarjan();
|
||||||
@ -17,8 +23,6 @@ cmComputeComponentGraph::cmComputeComponentGraph(Graph const& input)
|
|||||||
this->TransferEdges();
|
this->TransferEdges();
|
||||||
}
|
}
|
||||||
|
|
||||||
cmComputeComponentGraph::~cmComputeComponentGraph() = default;
|
|
||||||
|
|
||||||
void cmComputeComponentGraph::Tarjan()
|
void cmComputeComponentGraph::Tarjan()
|
||||||
{
|
{
|
||||||
int n = static_cast<int>(this->InputGraph.size());
|
int n = static_cast<int>(this->InputGraph.size());
|
||||||
|
@ -31,6 +31,9 @@ public:
|
|||||||
cmComputeComponentGraph(Graph const& input);
|
cmComputeComponentGraph(Graph const& input);
|
||||||
~cmComputeComponentGraph();
|
~cmComputeComponentGraph();
|
||||||
|
|
||||||
|
/** Run the computation. */
|
||||||
|
void Compute();
|
||||||
|
|
||||||
/** Get the adjacency list of the component graph. */
|
/** Get the adjacency list of the component graph. */
|
||||||
Graph const& GetComponentGraph() const { return this->ComponentGraph; }
|
Graph const& GetComponentGraph() const { return this->ComponentGraph; }
|
||||||
EdgeList const& GetComponentGraphEdges(int c) const
|
EdgeList const& GetComponentGraphEdges(int c) const
|
||||||
|
@ -626,6 +626,7 @@ void cmComputeLinkDepends::OrderLinkEntires()
|
|||||||
// constraints disallow it.
|
// constraints disallow it.
|
||||||
this->CCG =
|
this->CCG =
|
||||||
cm::make_unique<cmComputeComponentGraph>(this->EntryConstraintGraph);
|
cm::make_unique<cmComputeComponentGraph>(this->EntryConstraintGraph);
|
||||||
|
this->CCG->Compute();
|
||||||
|
|
||||||
// The component graph is guaranteed to be acyclic. Start a DFS
|
// The component graph is guaranteed to be acyclic. Start a DFS
|
||||||
// from every entry to compute a topological order for the
|
// from every entry to compute a topological order for the
|
||||||
|
@ -118,6 +118,7 @@ bool cmComputeTargetDepends::Compute()
|
|||||||
|
|
||||||
// Identify components.
|
// Identify components.
|
||||||
cmComputeComponentGraph ccg(this->InitialGraph);
|
cmComputeComponentGraph ccg(this->InitialGraph);
|
||||||
|
ccg.Compute();
|
||||||
if (this->DebugMode) {
|
if (this->DebugMode) {
|
||||||
this->DisplayComponents(ccg);
|
this->DisplayComponents(ccg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user