From 0a0793b2ca2712fb13411d59bed393583656fd2b Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Mon, 22 Feb 2016 22:52:11 -0500 Subject: [PATCH] dependency: No point scanning for circularity on 'add' --- src/dependency.cpp | 48 ++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/src/dependency.cpp b/src/dependency.cpp index 67491f42d..608f0b5bc 100644 --- a/src/dependency.cpp +++ b/src/dependency.cpp @@ -67,36 +67,42 @@ void dependencyGetBlocking (const Task& task, std::vector & blocking) // Returns true if the supplied task adds a cycle to the dependency chain. bool dependencyIsCircular (const Task& task) { - std::string task_uuid = task.get ("uuid"); - std::stack s; - s.push (task); - while (! s.empty ()) + // A new task has no UUID assigned yet, and therefore cannot be part of any + // dependency chain. + if (task.has ("uuid")) { - Task& current = s.top (); - std::vector deps_current; - current.getDependencies (deps_current); + auto task_uuid = task.get ("uuid"); - // 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++) + std::stack s; + s.push (task); + while (! s.empty ()) { - if (context.tdb2.get (deps_current[i], current)) + Task& current = s.top (); + std::vector 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! - return true; + if (task_uuid == current.get ("uuid")) + { + // Cycle found, initial task reached for the second time! + return true; + } + + s.push (current); } - - s.push (current); } - } - s.pop (); + s.pop (); + } } return false;