dependency: No point scanning for circularity on 'add'

This commit is contained in:
Paul Beckingham
2016-02-22 22:52:11 -05:00
parent 774cf3e2d9
commit 0a0793b2ca

View File

@@ -67,36 +67,42 @@ void dependencyGetBlocking (const Task& task, std::vector <Task>& blocking)
// Returns true if the supplied task adds a cycle to the dependency chain. // Returns true if the supplied task adds a cycle to the dependency chain.
bool dependencyIsCircular (const Task& task) bool dependencyIsCircular (const Task& task)
{ {
std::string task_uuid = task.get ("uuid");
std::stack <Task> s; // A new task has no UUID assigned yet, and therefore cannot be part of any
s.push (task); // dependency chain.
while (! s.empty ()) if (task.has ("uuid"))
{ {
Task& current = s.top (); auto task_uuid = task.get ("uuid");
std::vector <std::string> deps_current;
current.getDependencies (deps_current);
// This is a basic depth first search that always terminates given the std::stack <Task> s;
// assumption that any cycles in the dependency graph must have been s.push (task);
// introduced by the task that is being checked. while (! s.empty ())
// Since any previous cycles would have been prevented by this very
// function, this is a reasonable assumption.
for (unsigned int i = 0; i < deps_current.size (); i++)
{ {
if (context.tdb2.get (deps_current[i], current)) Task& current = s.top ();
std::vector <std::string> deps_current;
current.getDependencies (deps_current);
// This is a basic depth first search that always terminates given the
// assumption that any cycles in the dependency graph must have been
// introduced by the task that is being checked.
// Since any previous cycles would have been prevented by this very
// function, this is a reasonable assumption.
for (unsigned int i = 0; i < deps_current.size (); i++)
{ {
if (task_uuid == current.get ("uuid")) if (context.tdb2.get (deps_current[i], current))
{ {
// Cycle found, initial task reached for the second time! if (task_uuid == current.get ("uuid"))
return true; {
// Cycle found, initial task reached for the second time!
return true;
}
s.push (current);
} }
s.push (current);
} }
}
s.pop (); s.pop ();
}
} }
return false; return false;