Implemented IEquatable<T> to speed up equality comparisons.
Actor, CPos, CVec, WAngle, WPos, WRange, WRot and WVec structs now implement IEquatable<T> which means unboxing/casting costs can be eliminated. Also simplified the ToString method by concatenating components directly rather than using a format string since the overhead is a bit high for simple cases like this.
This commit is contained in:
@@ -21,7 +21,7 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding
|
||||
public class Actor : IScriptBindable, IScriptNotifyBind, ILuaTableBinding, ILuaEqualityBinding, ILuaToStringBinding, IEquatable<Actor>
|
||||
{
|
||||
public readonly ActorInfo Info;
|
||||
|
||||
@@ -158,7 +158,12 @@ namespace OpenRA
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var o = obj as Actor;
|
||||
return o != null && o.ActorID == ActorID;
|
||||
return o != null && Equals(o);
|
||||
}
|
||||
|
||||
public bool Equals(Actor other)
|
||||
{
|
||||
return ActorID == other.ActorID;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
|
||||
Reference in New Issue
Block a user