From 90621fd177660f94aa27ce5963506f814f859da2 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 1 Apr 2015 08:00:27 -0700 Subject: [PATCH] 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. --- src/build.cc | 6 ++---- 1 file 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* stack, string* err) { bool Plan::CheckDependencyCycle(Node* node, const vector& stack, string* err) { - vector::const_reverse_iterator ri = - find(stack.rbegin(), stack.rend(), node); - if (ri == stack.rend()) + vector::const_iterator start = find(stack.begin(), stack.end(), node); + if (start == stack.end()) return false; - vector::const_iterator start = find(stack.begin(), stack.end(), node); *err = "dependency cycle: "; for (vector::const_iterator i = start; i != stack.end(); ++i) { err->append((*i)->path()); -- 2.7.4