Implement IEquatable on structs.

Any struct which overrides object.Equals(object obj) should implement IEquatable<T> to gain a more efficient Equals(T other) overload. This overload will be used by hashing collections like Dictionary which enables them to check equality without boxing the struct.
This commit is contained in:
RoosterDragon
2019-09-14 00:33:27 +01:00
committed by teinarss
parent 4a609bbee8
commit 6c9fbd40dc
6 changed files with 33 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ using System;
namespace OpenRA.Primitives
{
public struct Size
public struct Size : IEquatable<Size>
{
public readonly int Width;
public readonly int Height;
@@ -46,6 +46,11 @@ namespace OpenRA.Primitives
public bool IsEmpty { get { return Width == 0 && Height == 0; } }
public bool Equals(Size other)
{
return this == other;
}
public override bool Equals(object obj)
{
if (!(obj is Size))