Fix CA1036
This commit is contained in:
@@ -619,6 +619,9 @@ dotnet_diagnostic.CA1010.severity = warning
|
|||||||
# Mark attributes with 'AttributeUsageAttribute'.
|
# Mark attributes with 'AttributeUsageAttribute'.
|
||||||
dotnet_diagnostic.CA1018.severity = warning
|
dotnet_diagnostic.CA1018.severity = warning
|
||||||
|
|
||||||
|
# Override methods on comparable types.
|
||||||
|
dotnet_diagnostic.CA1036.severity = warning
|
||||||
|
|
||||||
# Provide ObsoleteAttribute message.
|
# Provide ObsoleteAttribute message.
|
||||||
dotnet_diagnostic.CA1041.severity = warning
|
dotnet_diagnostic.CA1041.severity = warning
|
||||||
|
|
||||||
|
|||||||
@@ -56,17 +56,27 @@ namespace OpenRA.Primitives
|
|||||||
int Index(DelayedAction action)
|
int Index(DelayedAction action)
|
||||||
{
|
{
|
||||||
// Returns the index of the next action with a strictly greater time.
|
// 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)
|
if (index < 0)
|
||||||
return ~index;
|
return ~index;
|
||||||
while (index < actions.Count && action.CompareTo(actions[index]) >= 0)
|
while (index < actions.Count && DelayedAction.TimeComparer.Compare(action, actions[index]) >= 0)
|
||||||
index++;
|
index++;
|
||||||
return index;
|
return index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
readonly struct DelayedAction : IComparable<DelayedAction>
|
readonly struct DelayedAction
|
||||||
{
|
{
|
||||||
|
sealed class DelayedActionTimeComparer : IComparer<DelayedAction>
|
||||||
|
{
|
||||||
|
public int Compare(DelayedAction x, DelayedAction y)
|
||||||
|
{
|
||||||
|
return x.Time.CompareTo(y.Time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IComparer<DelayedAction> TimeComparer = new DelayedActionTimeComparer();
|
||||||
|
|
||||||
public readonly long Time;
|
public readonly long Time;
|
||||||
public readonly Action Action;
|
public readonly Action Action;
|
||||||
|
|
||||||
@@ -76,11 +86,6 @@ namespace OpenRA.Primitives
|
|||||||
Time = time;
|
Time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int CompareTo(DelayedAction other)
|
|
||||||
{
|
|
||||||
return Time.CompareTo(other.Time);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "Time: " + Time + " Action: " + Action;
|
return "Time: " + Time + " Action: " + Action;
|
||||||
|
|||||||
Reference in New Issue
Block a user