From 633216be143fe997624ab16505a5be49265dcaeb Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 23 Aug 2024 00:58:54 +1000 Subject: [PATCH] Remove `Bag` --- src/BizHawk.Common/CustomCollections.cs | 30 ------------------- .../Consoles/Nintendo/NES/BootGodDB.cs | 5 ++-- 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/BizHawk.Common/CustomCollections.cs b/src/BizHawk.Common/CustomCollections.cs index 83c7663454..98b55aa91f 100644 --- a/src/BizHawk.Common/CustomCollections.cs +++ b/src/BizHawk.Common/CustomCollections.cs @@ -1,42 +1,12 @@ using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; -using System.Linq; using System.Runtime.Serialization; using BizHawk.Common.CollectionExtensions; namespace BizHawk.Common { - /// Wrapper over WorkingDictionary<, List<>>. - [Serializable] - public class Bag : IEnumerable where TKey : notnull - { - private readonly WorkingDictionary> dictionary = new WorkingDictionary>(); - - public IList Keys => dictionary.Keys.ToList(); - - public List this[TKey key] - { -#pragma warning disable CS8603 // the only call to the index setter of `dictionary` is this index setter, which only takes non-null `List`s - get => dictionary[key]; -#pragma warning restore CS8603 - set => dictionary[key] = value; - } - - public void Add(TKey key, IEnumerable val) => this[key].AddRange(val); - - public void Add(TKey key, TValue val) => this[key].Add(val); - - public bool ContainsKey(TKey key) => dictionary.ContainsKey(key); - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - public IEnumerator GetEnumerator() => dictionary.Values.SelectMany(lv => lv).GetEnumerator(); - - public IEnumerator>> GetKVPEnumerator() => dictionary.GetEnumerator(); - } - public class SortedList : ICollection where T : IComparable { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs index f21dc53d02..a594b3e94b 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs @@ -4,6 +4,7 @@ using System.IO; using System.Xml; using System.Threading; using BizHawk.Common; +using BizHawk.Common.CollectionExtensions; using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Nintendo.NES @@ -17,7 +18,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES private readonly bool validate = true; - private readonly Bag _sha1Table = new Bag(); + private readonly Dictionary> _sha1Table = new(); private static BootGodDb instance; @@ -124,7 +125,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES case 4: if (xmlReader.NodeType == XmlNodeType.EndElement && xmlReader.Name == "cartridge") { - _sha1Table[currCart.Sha1].Add(currCart); + _sha1Table.GetValueOrPutNew(currCart.Sha1).Add(currCart); currCart = null; state = 5; }