Optimize IndexOfFrame function in TAStudio

This commit is contained in:
Morilli 2024-03-10 19:21:05 +01:00
parent 87197e0524
commit 05abb3adfa
1 changed files with 12 additions and 7 deletions

View File

@ -290,14 +290,19 @@ namespace BizHawk.Client.Common
{
public static int IndexOfFrame(this IList<TasBranch> list, int frame)
{
var branch = list
.Where(b => b.Frame == frame)
.OrderByDescending(b => b.TimeStamp)
.FirstOrDefault();
// intentionally not using linq here because this is called many times per frame
int index = -1;
var timeStamp = DateTime.MaxValue;
for (int i = 0; i < list.Count; i++)
{
if (list[i].Frame == frame && list[i].TimeStamp < timeStamp)
{
index = i;
timeStamp = list[i].TimeStamp;
}
}
return branch == null
? -1
: list.IndexOf(branch);
return index;
}
// TODO: stop relying on the index value of a branch