specialize pair's comparison to do something sensible with <char,Color> saving 16M.

This commit is contained in:
Chris Forbes
2011-03-05 21:51:49 +13:00
parent feecc70a4f
commit 269347ef01

View File

@@ -8,7 +8,9 @@
*/
#endregion
using System.Collections.Generic;
using System.Collections.Generic;
using System;
using System.Drawing;
namespace OpenRA.FileFormats
{
@@ -23,8 +25,8 @@ namespace OpenRA.FileFormats
Second = second;
}
static IEqualityComparer<T> tc = EqualityComparer<T>.Default;
static IEqualityComparer<U> uc = EqualityComparer<U>.Default;
internal static IEqualityComparer<T> tc = EqualityComparer<T>.Default;
internal static IEqualityComparer<U> uc = EqualityComparer<U>.Default;
public static bool operator ==(Pair<T, U> a, Pair<T, U> b)
{
@@ -55,8 +57,6 @@ namespace OpenRA.FileFormats
public static T AsFirst(Pair<T, U> p) { return p.First; }
public static U AsSecond(Pair<T, U> p) { return p.Second; }
public Pair<U, T> Swap() { return Pair.New(Second, First); }
public override string ToString()
{
return "({0},{1})".F(First, Second);
@@ -64,7 +64,19 @@ namespace OpenRA.FileFormats
}
public static class Pair
{
public static Pair<T, U> New<T, U>(T t, U u) { return new Pair<T, U>(t, u); }
{
public static Pair<T, U> New<T, U>(T t, U u) { return new Pair<T, U>(t, u); }
static Pair()
{
Pair<char,Color>.uc = new ColorEqualityComparer();
}
// avoid the default crappy one
class ColorEqualityComparer : IEqualityComparer<Color>
{
public bool Equals(Color x, Color y) { return x.ToArgb() == y.ToArgb(); }
public int GetHashCode(Color obj) { return obj.GetHashCode(); }
}
}
}