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:
@@ -15,7 +15,7 @@ using OpenRA.Scripting;
|
||||
|
||||
namespace OpenRA.Primitives
|
||||
{
|
||||
public struct Color : IScriptBindable
|
||||
public struct Color : IEquatable<Color>, IScriptBindable
|
||||
{
|
||||
readonly long argb;
|
||||
|
||||
@@ -200,6 +200,11 @@ namespace OpenRA.Primitives
|
||||
public byte G { get { return (byte)(argb >> 8); } }
|
||||
public byte B { get { return (byte)argb; } }
|
||||
|
||||
public bool Equals(Color other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Color))
|
||||
|
||||
Reference in New Issue
Block a user