Use RemoveAt instead of removing by value

CheatCollection.Add: replaced comparisons in lambda with overloaded ==
This commit is contained in:
YoshiRulz 2019-03-25 01:13:14 +10:00
parent 5f80e9d8e5
commit 4f5beb09a8
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
5 changed files with 12 additions and 35 deletions

View File

@ -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);
}
}
}

View File

@ -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--;
}

View File

@ -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)

View File

@ -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;
}

View File

@ -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);
}
}