diff --git a/.editorconfig b/.editorconfig index da4026108e..99652ef89f 100644 --- a/.editorconfig +++ b/.editorconfig @@ -619,6 +619,9 @@ dotnet_diagnostic.CA1010.severity = warning # Mark attributes with 'AttributeUsageAttribute'. dotnet_diagnostic.CA1018.severity = warning +# Override methods on comparable types. +dotnet_diagnostic.CA1036.severity = warning + # Provide ObsoleteAttribute message. dotnet_diagnostic.CA1041.severity = warning diff --git a/OpenRA.Game/Primitives/ActionQueue.cs b/OpenRA.Game/Primitives/ActionQueue.cs index 2f9337de49..401be66410 100644 --- a/OpenRA.Game/Primitives/ActionQueue.cs +++ b/OpenRA.Game/Primitives/ActionQueue.cs @@ -56,17 +56,27 @@ namespace OpenRA.Primitives int Index(DelayedAction action) { // Returns the index of the next action with a strictly greater time. - var index = actions.BinarySearch(action); + var index = actions.BinarySearch(action, DelayedAction.TimeComparer); if (index < 0) return ~index; - while (index < actions.Count && action.CompareTo(actions[index]) >= 0) + while (index < actions.Count && DelayedAction.TimeComparer.Compare(action, actions[index]) >= 0) index++; return index; } } - readonly struct DelayedAction : IComparable + readonly struct DelayedAction { + sealed class DelayedActionTimeComparer : IComparer + { + public int Compare(DelayedAction x, DelayedAction y) + { + return x.Time.CompareTo(y.Time); + } + } + + public static IComparer TimeComparer = new DelayedActionTimeComparer(); + public readonly long Time; public readonly Action Action; @@ -76,11 +86,6 @@ namespace OpenRA.Primitives Time = time; } - public int CompareTo(DelayedAction other) - { - return Time.CompareTo(other.Time); - } - public override string ToString() { return "Time: " + Time + " Action: " + Action;