From 6f1090c87fac727a8c155696cda0c0906299e7ee Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 6 Nov 2013 02:25:27 +0000 Subject: [PATCH] refactor cheatlist and watchlist to use MemoryDomain name indexing --- BizHawk.Client.Common/tools/CheatList.cs | 17 +---------------- BizHawk.Client.Common/tools/WatchList.cs | 15 ++------------- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index 7b89f00bd7..0f0ca015f1 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -333,7 +333,7 @@ namespace BizHawk.Client.Common { compare = Int32.Parse(vals[2], NumberStyles.HexNumber); } - MemoryDomain domain = DomainByName(vals[3]); + MemoryDomain domain = Global.Emulator.MemoryDomains[vals[3]]; bool ENABLED = vals[4] == "1"; string name = vals[5]; @@ -554,21 +554,6 @@ namespace BizHawk.Client.Common #region Privates - //TODO: remove this and make MemoryDomains in IEmulator support this - private static MemoryDomain DomainByName(string name) - { - //Attempts to find the memory domain by name, if it fails, it defaults to index 0 - foreach (MemoryDomain domain in Global.Emulator.MemoryDomains) - { - if (domain.Name == name) - { - return domain; - } - } - - return Global.Emulator.MemoryDomains.MainMemory; - } - private void CheatChanged(object sender) { if (Changed != null) diff --git a/BizHawk.Client.Common/tools/WatchList.cs b/BizHawk.Client.Common/tools/WatchList.cs index 7a2a2834ba..6a25b09f69 100644 --- a/BizHawk.Client.Common/tools/WatchList.cs +++ b/BizHawk.Client.Common/tools/WatchList.cs @@ -481,7 +481,7 @@ namespace BizHawk.Client.Common startIndex = line.IndexOf('\t') + 1; line = line.Substring(startIndex, line.Length - startIndex); //Domain temp = line.Substring(0, line.IndexOf('\t')); - memDomain = Global.Emulator.MemoryDomains[GetDomainPos(temp)]; + memDomain = Global.Emulator.MemoryDomains[temp]; } startIndex = line.IndexOf('\t') + 1; @@ -495,7 +495,7 @@ namespace BizHawk.Client.Common type, notes, bigEndian)); - _domain = Global.Emulator.MemoryDomains[GetDomainPos(domain)]; + _domain = Global.Emulator.MemoryDomains[domain]; } } @@ -511,17 +511,6 @@ namespace BizHawk.Client.Common return true; } - private static int GetDomainPos(string name) - { - //Attempts to find the memory domain by name, if it fails, it defaults to index 0 - for (int x = 0; x < Global.Emulator.MemoryDomains.Count; x++) - { - if (Global.Emulator.MemoryDomains[x].Name == name) - return x; - } - return 0; - } - #endregion } }