Rework PriorityQueue for performance.
- Providing the comparer as a type argument that is a struct allows the calls to be devirtualised, leading to approx a 3x performance improvement. - Use a single backing array, rather than a list of arrays.
This commit is contained in:
@@ -77,12 +77,8 @@ namespace OpenRA.Mods.Common.Pathfinder
|
||||
/// </summary>
|
||||
public readonly struct GraphConnection
|
||||
{
|
||||
public static readonly CostComparer ConnectionCostComparer = CostComparer.Instance;
|
||||
|
||||
public sealed class CostComparer : IComparer<GraphConnection>
|
||||
public readonly struct CostComparer : IComparer<GraphConnection>
|
||||
{
|
||||
public static readonly CostComparer Instance = new CostComparer();
|
||||
CostComparer() { }
|
||||
public int Compare(GraphConnection x, GraphConnection y)
|
||||
{
|
||||
return x.Cost.CompareTo(y.Cost);
|
||||
|
||||
Reference in New Issue
Block a user