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.
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());