From 15718875118d6804029fa768d8af095d877c7fac Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Mon, 9 Nov 2009 03:53:20 +0000 Subject: [PATCH] Move the to == from test, so as to return as soon as we find a path. The old way, we can waste time. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31916 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Graph.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Graph.cpp b/src/Graph.cpp index 8893aecfc9..f5e37b9c5d 100644 --- a/src/Graph.cpp +++ b/src/Graph.cpp @@ -154,10 +154,6 @@ Graph::EdgePath const Graph::getPath(int from, int to) while (!Q_.empty()) { int const current = Q_.front(); Q_.pop(); - if (current == to) { - found = true; - break; - } vector::const_iterator const beg = vertices_[current].out_arrows.begin(); @@ -170,9 +166,15 @@ Graph::EdgePath const Graph::getPath(int from, int to) visited_[cv] = true; Q_.push(cv); // FIXME This will not do for finding multiple paths. - // Perhaps we need a vector, or a set. + // Perhaps we need a vector, or a set. We'll also want + // to add this info, even if the node is visited, so + // outside this conditional. prev[cv] = pair(current, cit->edge); } + if (cv == to) { + found = true; + break; + } } } if (!found)