diff options
author | Nico Weber <nicolasweber@gmx.de> | 2015-04-01 15:00:27 (GMT) |
---|---|---|
committer | Nico Weber <nicolasweber@gmx.de> | 2015-04-01 15:00:27 (GMT) |
commit | 90621fd177660f94aa27ce5963506f814f859da2 (patch) | |
tree | 6c9aac067cea4e6dbc7c49da6f9839de4bf99c76 /src | |
parent | 813205b43c63239c7e37f9e296d345d55b12d565 (diff) | |
download | Ninja-90621fd177660f94aa27ce5963506f814f859da2.zip Ninja-90621fd177660f94aa27ce5963506f814f859da2.tar.gz Ninja-90621fd177660f94aa27ce5963506f814f859da2.tar.bz2 |
Cleanup: Don't search stack for cycle elements twice.
The common case is that there is no cycle. In that case,
CheckDependencyCycle() searched the stack for a dupe from the back,
wouldn't find one, and return false.
If there was a cycle, it would then search again from the front
(probably because the push_back() that used to be here would invalidate
the ri iterator).
Since the push_back() is gone, just search from the front once. No
intended behavior change.
Diffstat (limited to 'src')
-rw-r--r-- | src/build.cc | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/build.cc b/src/build.cc index c51ce53..9f40d2d 100644 --- a/src/build.cc +++ b/src/build.cc @@ -318,12 +318,10 @@ bool Plan::AddSubTarget(Node* node, vector<Node*>* stack, string* err) { bool Plan::CheckDependencyCycle(Node* node, const vector<Node*>& stack, string* err) { - vector<Node*>::const_reverse_iterator ri = - find(stack.rbegin(), stack.rend(), node); - if (ri == stack.rend()) + vector<Node*>::const_iterator start = find(stack.begin(), stack.end(), node); + if (start == stack.end()) return false; - vector<Node*>::const_iterator start = find(stack.begin(), stack.end(), node); *err = "dependency cycle: "; for (vector<Node*>::const_iterator i = start; i != stack.end(); ++i) { err->append((*i)->path()); |