From 69ea44310b0c288ee4e4038f6b66bba2f656654a Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sun, 6 Mar 2011 08:59:25 +1300 Subject: [PATCH] remove another 40M/min of boxing junk by specializing the key comparer on SpriteFont's dict --- OpenRA.FileFormats/Primitives/Pair.cs | 10 +++++++++- OpenRA.Game/Graphics/SpriteFont.cs | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/OpenRA.FileFormats/Primitives/Pair.cs b/OpenRA.FileFormats/Primitives/Pair.cs index 60f67df522..7603795801 100644 --- a/OpenRA.FileFormats/Primitives/Pair.cs +++ b/OpenRA.FileFormats/Primitives/Pair.cs @@ -60,7 +60,15 @@ namespace OpenRA.FileFormats public override string ToString() { return "({0},{1})".F(First, Second); - } + } + + class PairEqualityComparer : IEqualityComparer> + { + public bool Equals(Pair x, Pair y) { return x == y; } + public int GetHashCode(Pair obj) { return obj.GetHashCode(); } + } + + public static IEqualityComparer> EqualityComparer { get { return new PairEqualityComparer(); } } } public static class Pair diff --git a/OpenRA.Game/Graphics/SpriteFont.cs b/OpenRA.Game/Graphics/SpriteFont.cs index 8ba3cd9d24..4dbaf0b01c 100644 --- a/OpenRA.Game/Graphics/SpriteFont.cs +++ b/OpenRA.Game/Graphics/SpriteFont.cs @@ -29,7 +29,8 @@ namespace OpenRA.Graphics throw new InvalidOperationException("FT_New_Face failed"); FT.FT_Set_Pixel_Sizes(face, 0, (uint)size); - glyphs = new Cache, GlyphInfo>(CreateGlyph); + glyphs = new Cache, GlyphInfo>(CreateGlyph, + Pair.EqualityComparer); // setup a 1-channel SheetBuilder for our private use if (builder == null) builder = new SheetBuilder(TextureChannel.Alpha);