From 02570b2063c7a1e79122ca4c4073051627af8b53 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 10 Dec 2022 15:13:59 +0000 Subject: [PATCH] Store graph vertices in a std::vector It doesn't make much of a difference to performance, but it does simplify the code a little and silence a few compiler warnings. --- src/api/sorting/plugin_graph.cpp | 25 ++----------------------- src/api/sorting/plugin_graph.h | 2 +- src/api/sorting/plugin_sorting_data.cpp | 3 +++ src/api/sorting/plugin_sorting_data.h | 2 ++ 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 3b1e5cc0..a5b18d37 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -45,8 +45,6 @@ using std::vector; namespace loot { typedef boost::graph_traits::edge_descriptor edge_t; typedef boost::graph_traits::edge_iterator edge_it; -typedef boost::associative_property_map> - vertex_map_t; class CycleDetector : public boost::dfs_visitor<> { public: @@ -322,35 +320,16 @@ void PluginGraph::CheckForCycles() const { logger->trace("Checking plugin graph for cycles..."); } - std::map indexMap; - const auto vertexIndexMap = vertex_map_t(indexMap); - size_t i = 0; - // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDelete) - BGL_FORALL_VERTICES(v, graph_, RawPluginGraph) { - put(vertexIndexMap, v, i++); - } - - boost::depth_first_search( - graph_, visitor(CycleDetector()).vertex_index_map(vertexIndexMap)); + boost::depth_first_search(graph_, visitor(CycleDetector())); } std::vector PluginGraph::TopologicalSort() const { - // Build an index map, which std::list-based VertexList graphs don't have. - std::map indexMap; - const auto vertexIndexMap = vertex_map_t(indexMap); - size_t i = 0; - BGL_FORALL_VERTICES(v, graph_, RawPluginGraph) { - put(vertexIndexMap, v, i++); - } - std::vector sortedVertices; auto logger = getLogger(); if (logger) { logger->trace("Performing topological sort on plugin graph..."); } - boost::topological_sort(graph_, - std::back_inserter(sortedVertices), - boost::vertex_index_map(vertexIndexMap)); + boost::topological_sort(graph_, std::back_inserter(sortedVertices)); std::reverse(sortedVertices.begin(), sortedVertices.end()); diff --git a/src/api/sorting/plugin_graph.h b/src/api/sorting/plugin_graph.h index cd41f72f..81865add 100644 --- a/src/api/sorting/plugin_graph.h +++ b/src/api/sorting/plugin_graph.h @@ -41,7 +41,7 @@ namespace loot { typedef boost::adjacency_list diff --git a/src/api/sorting/plugin_sorting_data.cpp b/src/api/sorting/plugin_sorting_data.cpp index 910ae277..3208e710 100644 --- a/src/api/sorting/plugin_sorting_data.cpp +++ b/src/api/sorting/plugin_sorting_data.cpp @@ -49,6 +49,9 @@ std::vector GetPluginsSubset( return pluginsSubset; } +PluginSortingData::PluginSortingData() : + plugin_(nullptr), numOverrideFormIDs(0) {} + PluginSortingData::PluginSortingData( const PluginSortingInterface* plugin, const PluginMetadata& masterlistMetadata, diff --git a/src/api/sorting/plugin_sorting_data.h b/src/api/sorting/plugin_sorting_data.h index 86e0c66e..8443b79b 100644 --- a/src/api/sorting/plugin_sorting_data.h +++ b/src/api/sorting/plugin_sorting_data.h @@ -31,6 +31,8 @@ namespace loot { class PluginSortingData { public: + explicit PluginSortingData(); + /** * This stores a copy of the plugin pointer that is passed to it, so * PluginSortingData objects must not live longer than the Plugin objects