diff --git a/BizHawk.Client.Common/tools/RamSearchEngine.cs b/BizHawk.Client.Common/tools/RamSearchEngine.cs index 90661160de..ecdbbc7857 100644 --- a/BizHawk.Client.Common/tools/RamSearchEngine.cs +++ b/BizHawk.Client.Common/tools/RamSearchEngine.cs @@ -340,14 +340,30 @@ namespace BizHawk.Client.Common } } - public void RemoveRange(IEnumerable addresses) + /// + /// Remove a set of watches + /// However, this should not be used with large data sets (100k or more) as it uses a contains logic to perform the task + /// + public void RemoveSmallWatchRange(IEnumerable watches) { if (_keepHistory) { _history.AddState(_watchList); } - _watchList = _watchList.Where(x => !addresses.Contains(x.Address)).ToList(); + var addresses = watches.Select(x => x.Address ?? 0); + var removeList = _watchList.Where(x => !addresses.Contains(x.Address)).ToList(); + } + + public void RemoveRange(IEnumerable indices) + { + if (_keepHistory) + { + _history.AddState(_watchList); + } + + var removeList = indices.Select(i => _watchList[i]); + _watchList = _watchList.Except(removeList).ToList(); } public void AddRange(List addresses, bool append) diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs index 0e7365fd8c..d8460c054b 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamSearch.cs @@ -783,9 +783,7 @@ namespace BizHawk.Client.EmuHawk if (indices.Any()) { SetRemovedMessage(indices.Count); - - var addresses = indices.Select(index => _searches[index].Address ?? 0).ToList(); - _searches.RemoveRange(addresses); + _searches.RemoveRange(indices); WatchListView.ItemCount = _searches.Count; SetTotal(); @@ -805,12 +803,14 @@ namespace BizHawk.Client.EmuHawk var watches = new WatchList(_settings.Domain); watches.Load(file.FullName, append); - var addresses = watches.Where(x => !x.IsSeparator).Select(x => x.Address ?? 0).ToList(); + + var watchList = watches.Where(x => !x.IsSeparator); + var addresses = watchList.Select(x => x.Address ?? 0).ToList(); if (truncate) { SetRemovedMessage(addresses.Count); - _searches.RemoveRange(addresses); + _searches.RemoveSmallWatchRange(watchList); } else { @@ -867,7 +867,7 @@ namespace BizHawk.Client.EmuHawk { if (GlobalWin.Tools.Has()) { - _searches.RemoveRange(GlobalWin.Tools.RamWatch.AddressList); + _searches.RemoveSmallWatchRange(GlobalWin.Tools.RamWatch.Watches); WatchListView.ItemCount = _searches.Count; SetTotal(); } @@ -1479,7 +1479,7 @@ namespace BizHawk.Client.EmuHawk SetRemovedMessage(outOfRangeAddresses.Count); - _searches.RemoveRange(outOfRangeAddresses); + //_searches.RemoveRange(outOfRangeAddresses); Remove TODO WatchListView.ItemCount = _searches.Count; SetTotal(); diff --git a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs index 3cc5ba4238..4cf663b79a 100644 --- a/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs +++ b/BizHawk.Client.EmuHawk/tools/Watch/RamWatch.cs @@ -73,11 +73,11 @@ namespace BizHawk.Client.EmuHawk #region Properties - public IEnumerable AddressList + public IEnumerable Watches { get { - return _watches.Where(x => !x.IsSeparator).Select(x => x.Address ?? 0); + return _watches.Where(x => !x.IsSeparator); } }