(guess) Remove `RamSearchEngine._isSorted`

This commit is contained in:
YoshiRulz 2024-08-16 23:43:11 +10:00
parent 250dc16748
commit eee059607a
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
2 changed files with 5 additions and 8 deletions

View File

@ -23,7 +23,6 @@ namespace BizHawk.Client.Common.RamSearchEngine
private IMiniWatch[] _watchList = Array.Empty<IMiniWatch>();
private readonly SearchEngineSettings _settings;
private readonly UndoHistory<IEnumerable<IMiniWatch>> _history = new UndoHistory<IEnumerable<IMiniWatch>>(true, new List<IMiniWatch>()); //TODO use IList instead of IEnumerable and stop calling `.ToArray()` (i.e. cloning) on reads and writes?
private bool _isSorted = true; // Tracks whether or not the array is sorted by address, if it is, binary search can be used for finding watches
public RamSearchEngine(SearchEngineSettings settings, IMemoryDomains memoryDomains)
{
@ -120,11 +119,11 @@ namespace BizHawk.Client.Common.RamSearchEngine
return before - _watchList.Length;
}
public bool Preview(long address)
public bool Preview(int index)
{
var listOfOne = Enumerable.Repeat(_isSorted
? _watchList.BinarySearch(w => w.Address, address)
: _watchList.FirstOrDefault(w => w.Address == address), 1);
var addressWatch = _watchList[index];
addressWatch.Update(PreviousType.Original, _settings.Domain, _settings.BigEndian);
IMiniWatch[] listOfOne = [ addressWatch ];
return _compareTo switch
{
@ -249,12 +248,10 @@ namespace BizHawk.Client.Common.RamSearchEngine
};
_watchList = (append ? _watchList.Concat(list) : list).ToArray();
_isSorted = false; //TODO can this be smarter, such as by inserting instead of appending?
}
public void Sort(string column, bool reverse)
{
_isSorted = column == WatchList.Address && !reverse;
switch (column)
{
case WatchList.Address:

View File

@ -188,7 +188,7 @@ namespace BizHawk.Client.EmuHawk
var nextColor = Color.White;
var search = _searches[index];
var isCheat = MainForm.CheatList.IsActive(_settings.Domain, search.Address);
var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(search.Address);
var isWeeded = Settings.PreviewMode && !_forcePreviewClear && _searches.Preview(index);
if (!search.IsValid)
{