Optimize RamSearchEngine.Preview
This commit is contained in:
parent
53436e81f5
commit
3c218c6642
|
@ -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)
|
||||
{
|
||||
|
@ -153,11 +152,10 @@ 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];
|
||||
IMiniWatch[] listOfOne = [ addressWatch ];
|
||||
|
||||
return _compareTo switch
|
||||
{
|
||||
|
@ -284,12 +282,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:
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue