plugin manager: optimize plugin dependency sorting
Previously, PluginManager.loadPlugins would make a graph of reverse dependencies, topologically sort them, then reverse the list. This commit changes loadPlugins to build a graph of dependencies so no reversal is needed. Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
@@ -26,7 +26,6 @@ package net.runelite.client.plugins;
|
|||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.common.graph.Graph;
|
import com.google.common.graph.Graph;
|
||||||
import com.google.common.graph.GraphBuilder;
|
import com.google.common.graph.GraphBuilder;
|
||||||
import com.google.common.graph.Graphs;
|
import com.google.common.graph.Graphs;
|
||||||
@@ -320,8 +319,7 @@ public class PluginManager
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Class<Plugin> pluginClass = (Class<Plugin>) clazz;
|
graph.addNode((Class<Plugin>) clazz);
|
||||||
graph.addNode(pluginClass);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build plugin graph
|
// Build plugin graph
|
||||||
@@ -333,7 +331,7 @@ public class PluginManager
|
|||||||
{
|
{
|
||||||
if (graph.nodes().contains(pluginDependency.value()))
|
if (graph.nodes().contains(pluginDependency.value()))
|
||||||
{
|
{
|
||||||
graph.putEdge(pluginClazz, pluginDependency.value());
|
graph.putEdge(pluginDependency.value(), pluginClazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -344,7 +342,6 @@ public class PluginManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<Class<? extends Plugin>> sortedPlugins = topologicalSort(graph);
|
List<Class<? extends Plugin>> sortedPlugins = topologicalSort(graph);
|
||||||
sortedPlugins = Lists.reverse(sortedPlugins);
|
|
||||||
|
|
||||||
int loaded = 0;
|
int loaded = 0;
|
||||||
List<Plugin> newPlugins = new ArrayList<>();
|
List<Plugin> newPlugins = new ArrayList<>();
|
||||||
|
|||||||
Reference in New Issue
Block a user