From 264c6756a098ce7d6e2ea0c231607b7af934d2d6 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 9 Sep 2018 21:02:28 +0100 Subject: [PATCH] Don't iterate over vertex pairs twice This doesn't actually improve performance for me, as EdgeCreatesCycle() tends to fail fast, but it's less obviously slow. --- src/api/sorting/plugin_sorter.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/api/sorting/plugin_sorter.cpp b/src/api/sorting/plugin_sorter.cpp index c3891626..c39d99a2 100644 --- a/src/api/sorting/plugin_sorter.cpp +++ b/src/api/sorting/plugin_sorter.cpp @@ -720,19 +720,16 @@ void PluginSorter::AddTieBreakEdges() { // possible result. This can be enforced by adding edges between all vertices // that aren't already linked. Use existing load order to decide the direction // of these edges. - for (const auto& vertex : - boost::make_iterator_range(boost::vertices(graph_))) { + vertex_it vit, vitend; + for (tie(vit, vitend) = boost::vertices(graph_); vit != vitend; ++vit) { + vertex_t vertex = *vit; if (logger_) { logger_->trace("Adding tie-break edges to vertex for \"{}\"", graph_[vertex].GetName()); } - for (const auto& otherVertex : - boost::make_iterator_range(boost::vertices(graph_))) { - if (vertex == otherVertex || - boost::edge(vertex, otherVertex, graph_).second || - boost::edge(otherVertex, vertex, graph_).second) - continue; + for (vertex_it vit2 = std::next(vit); vit2 != vitend; ++vit2) { + vertex_t otherVertex = *vit2; vertex_t toVertex, fromVertex; if (ComparePlugins(graph_[vertex].GetName(),