From 269dd38402c9eebef168dd97361251d93dd64d22 Mon Sep 17 00:00:00 2001 From: Benjamin Hess Date: Fri, 30 Mar 2012 03:17:05 +0800 Subject: [PATCH] changed skin element lookup to dictionary (was linear search) --- Vocaluxe/Base/CTheme.cs | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/Vocaluxe/Base/CTheme.cs b/Vocaluxe/Base/CTheme.cs index 639ebdac..03a560f8 100644 --- a/Vocaluxe/Base/CTheme.cs +++ b/Vocaluxe/Base/CTheme.cs @@ -45,7 +45,7 @@ namespace Vocaluxe.Base public string Path; public string FileName; - public List SkinList; + public Dictionary SkinList; public List VideoList; public SColors ThemeColors; @@ -163,16 +163,18 @@ namespace Vocaluxe.Base { string value = String.Empty; + // load skins/textures - for (int i = 0; i < _Skins[index].SkinList.Count; i++) + List keys = new List(_Skins[index].SkinList.Keys); + + foreach (string name in keys) { - CHelper.GetValueFromXML("//root/Skins/" + _Skins[index].SkinList[i].Name, navigator, ref value, String.Empty); - SkinElement sk = new SkinElement(); - sk.Name = _Skins[index].SkinList[i].Name; + CHelper.GetValueFromXML("//root/Skins/" + name, navigator, ref value, String.Empty); + SkinElement sk = _Skins[index].SkinList[name]; sk.Value = value; sk.VideoIndex = -1; sk.Texture = CDraw.AddTexture(Path.Combine(_Skins[index].Path, sk.Value)); - _Skins[index].SkinList[i] = sk; + _Skins[index].SkinList[name] = sk; } // load videos @@ -199,9 +201,9 @@ namespace Vocaluxe.Base { for (int i = 0; i < _Skins.Count; i++) { - for (int j = 0; j < _Skins[i].SkinList.Count; j++) + foreach (SkinElement sk in _Skins[i].SkinList.Values) { - STexture Texture = _Skins[i].SkinList[j].Texture; + STexture Texture = sk.Texture; CDraw.RemoveTexture(ref Texture); } @@ -335,7 +337,7 @@ namespace Vocaluxe.Base #region Skins writer.WriteStartElement("Skins"); - foreach (SkinElement element in _Skins[SkinIndex].SkinList) + foreach (SkinElement element in _Skins[SkinIndex].SkinList.Values) { writer.WriteElementString(element.Name, element.Value); } @@ -489,14 +491,14 @@ namespace Vocaluxe.Base skin.Path = path; skin.FileName = file; - skin.SkinList = new List(); + skin.SkinList = new Dictionary(); List names = CHelper.GetValuesFromXML("Skins", navigator); foreach (string str in names) { SkinElement sk = new SkinElement(); sk.Name = str; sk.Value = String.Empty; - skin.SkinList.Add(sk); + skin.SkinList[str] = sk; } skin.VideoList = new List(); @@ -573,16 +575,9 @@ namespace Vocaluxe.Base public static STexture GetSkinTexture(string TextureName) { int SkinIndex = GetSkinIndex(); - if (SkinIndex != -1) + if (SkinIndex != -1 && TextureName != null && _Skins[SkinIndex].SkinList.ContainsKey(TextureName)) { - for (int i = 0; i < _Skins[SkinIndex].SkinList.Count; i++) - { - SkinElement sk = _Skins[SkinIndex].SkinList[i]; - if (sk.Name == TextureName) - { - return sk.Texture; - } - } + return _Skins[SkinIndex].SkinList[TextureName].Texture; } return new STexture(-1); } @@ -599,7 +594,7 @@ namespace Vocaluxe.Base private static string GetSkinFileName(string SkinName, int SkinIndex, bool ReturnPath) { - foreach (SkinElement sk in _Skins[SkinIndex].SkinList) + foreach (SkinElement sk in _Skins[SkinIndex].SkinList.Values) { if (sk.Name == SkinName) {