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:
@@ -13,7 +13,7 @@ using System;
|
||||
|
||||
namespace OpenRA.Primitives
|
||||
{
|
||||
public struct Rectangle
|
||||
public struct Rectangle : IEquatable<Rectangle>
|
||||
{
|
||||
// TODO: Make these readonly: this will require a lot of changes to the UI logic
|
||||
public int X;
|
||||
@@ -76,6 +76,11 @@ namespace OpenRA.Primitives
|
||||
return Contains(pt.X, pt.Y);
|
||||
}
|
||||
|
||||
public bool Equals(Rectangle other)
|
||||
{
|
||||
return this == other;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (!(obj is Rectangle))
|
||||
|
||||
Reference in New Issue
Block a user