diff options
author | Nico Weber <nicolasweber@gmx.de> | 2015-04-01 15:18:49 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2015-04-01 15:18:49 (GMT) |
commit | a960fe2bf972467725626ae70422f44292be2834 (patch) | |
tree | 6c9aac067cea4e6dbc7c49da6f9839de4bf99c76 | |
parent | 9900cb3b3884fbd5199fa7c1060b4cd3b7514b8f (diff) | |
parent | 90621fd177660f94aa27ce5963506f814f859da2 (diff) | |
download | Ninja-a960fe2bf972467725626ae70422f44292be2834.zip Ninja-a960fe2bf972467725626ae70422f44292be2834.tar.gz Ninja-a960fe2bf972467725626ae70422f44292be2834.tar.bz2 |
Merge pull request #950 from nico/cleanup
Simplify Plan's cycle detection code. No behavior change.
-rw-r--r-- | src/build.cc | 21 | ||||
-rw-r--r-- | src/build.h | 3 |
2 files changed, 10 insertions, 14 deletions
diff --git a/src/build.cc b/src/build.cc index d898929..9f40d2d 100644 --- a/src/build.cc +++ b/src/build.cc @@ -278,7 +278,7 @@ bool Plan::AddSubTarget(Node* node, vector<Node*>* stack, string* err) { return false; } - if (CheckDependencyCycle(node, stack, err)) + if (CheckDependencyCycle(node, *stack, err)) return false; if (edge->outputs_ready()) @@ -316,23 +316,18 @@ bool Plan::AddSubTarget(Node* node, vector<Node*>* stack, string* err) { return true; } -bool Plan::CheckDependencyCycle(Node* node, vector<Node*>* stack, string* err) { - vector<Node*>::reverse_iterator ri = - find(stack->rbegin(), stack->rend(), node); - if (ri == stack->rend()) +bool Plan::CheckDependencyCycle(Node* node, const vector<Node*>& stack, + string* err) { + vector<Node*>::const_iterator start = find(stack.begin(), stack.end(), node); + if (start == stack.end()) return false; - // Add this node onto the stack to make it clearer where the loop - // is. - stack->push_back(node); - - vector<Node*>::iterator start = find(stack->begin(), stack->end(), node); *err = "dependency cycle: "; - for (vector<Node*>::iterator i = start; i != stack->end(); ++i) { - if (i != start) - err->append(" -> "); + for (vector<Node*>::const_iterator i = start; i != stack.end(); ++i) { err->append((*i)->path()); + err->append(" -> "); } + err->append(node->path()); return true; } diff --git a/src/build.h b/src/build.h index 5d5db80..4b48c5f 100644 --- a/src/build.h +++ b/src/build.h @@ -69,7 +69,8 @@ struct Plan { private: bool AddSubTarget(Node* node, vector<Node*>* stack, string* err); - bool CheckDependencyCycle(Node* node, vector<Node*>* stack, string* err); + bool CheckDependencyCycle(Node* node, const vector<Node*>& stack, + string* err); void NodeFinished(Node* node); /// Submits a ready edge as a candidate for execution. |