From 4f5beb09a8efe9ff7e7121e290bc302d59e29371 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 25 Mar 2019 01:13:14 +1000 Subject: [PATCH] Use RemoveAt instead of removing by value CheatCollection.Add: replaced comparisons in lambda with overloaded == --- BizHawk.Client.Common/RecentFiles.cs | 2 +- BizHawk.Client.Common/movie/SubtitleList.cs | 2 +- BizHawk.Client.Common/tools/CheatList.cs | 20 ++++++------------- BizHawk.Common/UndoHistory.cs | 19 ++---------------- .../Hardware/Display/AmstradGateArray.cs | 4 ++-- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/BizHawk.Client.Common/RecentFiles.cs b/BizHawk.Client.Common/RecentFiles.cs index 889c916f3a..ebf6447744 100644 --- a/BizHawk.Client.Common/RecentFiles.cs +++ b/BizHawk.Client.Common/RecentFiles.cs @@ -80,7 +80,7 @@ namespace BizHawk.Client.Common if (recentlist.Count > MAX_RECENT_FILES) { - recentlist.Remove(recentlist[recentlist.Count - 1]); + recentlist.RemoveAt(recentlist.Count - 1); } } } diff --git a/BizHawk.Client.Common/movie/SubtitleList.cs b/BizHawk.Client.Common/movie/SubtitleList.cs index d3f5fee533..d878b37844 100644 --- a/BizHawk.Client.Common/movie/SubtitleList.cs +++ b/BizHawk.Client.Common/movie/SubtitleList.cs @@ -104,7 +104,7 @@ namespace BizHawk.Client.Common if (i > 0 && lastframe == subs[i].Frame) { subs[i].Message = subs[i - 1].Message + " " + subs[i].Message; - subs.Remove(subs[i - 1]); + subs.RemoveAt(i - 1); i--; } diff --git a/BizHawk.Client.Common/tools/CheatList.cs b/BizHawk.Client.Common/tools/CheatList.cs index c0a2c50935..5c69ba29f7 100644 --- a/BizHawk.Client.Common/tools/CheatList.cs +++ b/BizHawk.Client.Common/tools/CheatList.cs @@ -133,11 +133,8 @@ namespace BizHawk.Client.Common else { cheat.Changed += CheatChanged; - if (Contains(cheat)) - { - _cheatList.Remove(Global.CheatList.FirstOrDefault(c => c.Domain == cheat.Domain && c.Address == cheat.Address)); - } - + var foundIndex = _cheatList.FindIndex(c => c == cheat); + if (foundIndex != -1) _cheatList.RemoveAt(foundIndex); _cheatList.Add(cheat); } @@ -194,15 +191,10 @@ namespace BizHawk.Client.Common public bool Remove(Watch watch) { - var cheat = _cheatList.FirstOrDefault(c => c == watch); - if (cheat != (Cheat)null) - { - _cheatList.Remove(cheat); - Changes = true; - return true; - } - - return false; + var foundIndex = _cheatList.FindIndex(c => c == watch); + if (foundIndex == -1) return false; + _cheatList.RemoveAt(foundIndex); + return Changes = true; } public bool Contains(Cheat cheat) diff --git a/BizHawk.Common/UndoHistory.cs b/BizHawk.Common/UndoHistory.cs index a391493256..51dcaa7c25 100644 --- a/BizHawk.Common/UndoHistory.cs +++ b/BizHawk.Common/UndoHistory.cs @@ -40,23 +40,8 @@ namespace BizHawk.Common { if (Enabled) { - if (_curPos < _history.Count) - { - for (var i = _curPos + 1; i <= _history.Count; i++) - { - _history.Remove(_history[i - 1]); - } - } - - // TODO: don't assume we are one over, since MaxUndoLevels is public, it could be set to a small number after a large list has occured - if (_history.Count > MaxUndoLevels) - { - foreach (var item in _history.Take(_history.Count - MaxUndoLevels)) - { - _history.Remove(item); - } - } - + for (int i = _curPos, end = _history.Count - 2; i < end; i++) _history.RemoveAt(i); + while (_history.Count > MaxUndoLevels) _history.RemoveAt(0); // using a while rather than an if because MaxUndoLevels is public and could be lowered between calls _history.Add(newState.ToList()); _curPos = _history.Count; } diff --git a/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Display/AmstradGateArray.cs b/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Display/AmstradGateArray.cs index 9d9f262b2a..6c5033a324 100644 --- a/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Display/AmstradGateArray.cs +++ b/BizHawk.Emulation.Cores/Computers/AmstradCPC/Hardware/Display/AmstradGateArray.cs @@ -1059,11 +1059,11 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC var excessR = excessL + (padPos % 2); for (int i = 0; i < excessL; i++) { - lCop.Remove(lCop[0]); + lCop.RemoveAt(0); } for (int i = 0; i < excessL; i++) { - lCop.Remove(lCop[lCop.Count - 1]); + lCop.RemoveAt(lCop.Count - 1); } }