From 6252c58a3f32ff9552ef450028c2b63c48153439 Mon Sep 17 00:00:00 2001 From: adelikat Date: Wed, 1 Jan 2014 21:56:35 +0000 Subject: [PATCH] Ram Search - don't attempt to binary search if the list is not sorted! This fixes exceptions thrown when using column click. The consequence is that preview mode is significantly slower after sorting by anything other than Address ascending, only really impacts large domains such as N64 domains --- BizHawk.Client.Common/tools/RamSearchEngine.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/BizHawk.Client.Common/tools/RamSearchEngine.cs b/BizHawk.Client.Common/tools/RamSearchEngine.cs index 3dcd58589c..532cd5d9b8 100644 --- a/BizHawk.Client.Common/tools/RamSearchEngine.cs +++ b/BizHawk.Client.Common/tools/RamSearchEngine.cs @@ -21,6 +21,7 @@ namespace BizHawk.Client.Common private readonly Settings _settings = new Settings(); private readonly UndoHistory _history = new UndoHistory(true); private bool _keepHistory = true; + private bool _isSorted = true; // Tracks whether or not the list is sorted by address, if it is, binary search can be used for finding watches public RamSearchEngine(Settings settings) { @@ -190,7 +191,16 @@ namespace BizHawk.Client.Common public bool Preview(int address) { - var listOfOne = Enumerable.Repeat(_watchList.BinarySearch(x => x.Address, address), 1); + IEnumerable listOfOne; + + if (_isSorted) + { + listOfOne = Enumerable.Repeat(_watchList.BinarySearch(x => x.Address, address), 1); + } + else + { + listOfOne = Enumerable.Repeat(_watchList.FirstOrDefault(x => x.Address == address), 1); + } switch (_compareTo) { @@ -400,6 +410,7 @@ namespace BizHawk.Client.Common public void Sort(string column, bool reverse) { + _isSorted = false; switch (column) { case WatchList.ADDRESS: @@ -410,6 +421,7 @@ namespace BizHawk.Client.Common else { _watchList = _watchList.OrderBy(x => x.Address).ToList(); + _isSorted = true; } break;