From e5aca584a2c41149b9dfc4a4be80cb14be91a1b3 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Thu, 7 Nov 2013 13:56:16 +0100 Subject: [PATCH] Avoid boxing in Skin dictionary. closes #156 --- spine-csharp/src/Skin.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/spine-csharp/src/Skin.cs b/spine-csharp/src/Skin.cs index a0b997057..aed149be4 100644 --- a/spine-csharp/src/Skin.cs +++ b/spine-csharp/src/Skin.cs @@ -38,9 +38,10 @@ namespace Spine { /// Stores attachments by slot index and attachment name. public class Skin { internal String name; + private Dictionary, Attachment> attachments = + new Dictionary, Attachment>(AttachmentComparer.Instance); public String Name { get { return name; } } - private Dictionary, Attachment> attachments = new Dictionary, Attachment>(); public Skin (String name) { if (name == null) throw new ArgumentNullException("name cannot be null."); @@ -86,5 +87,18 @@ namespace Spine { } } } + + // Avoids boxing in the dictionary. + private class AttachmentComparer : IEqualityComparer> { + internal static readonly AttachmentComparer Instance = new AttachmentComparer(); + + bool IEqualityComparer>.Equals (KeyValuePair o1, KeyValuePair o2) { + return o1.Key == o2.Key && o1.Value == o2.Value; + } + + int IEqualityComparer>.GetHashCode (KeyValuePair o) { + return o.Key; + } + } } }