Optimize speed and allocations of TasMovieMarker.Previous[OrCurrent]

was quite a ridiculous amount of allocations due the amount of calls to this functions
This commit is contained in:
Morilli 2024-03-07 22:52:53 +01:00
parent 592eb34370
commit 674997b345
1 changed files with 5 additions and 8 deletions

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using BizHawk.Common.CollectionExtensions;
namespace BizHawk.Client.Common
{
@ -296,18 +297,14 @@ namespace BizHawk.Client.Common
public TasMovieMarker Previous(int currentFrame)
{
return this
.Where(m => m.Frame < currentFrame)
.OrderBy(m => m.Frame)
.LastOrDefault();
return PreviousOrCurrent(currentFrame - 1);
}
public TasMovieMarker PreviousOrCurrent(int currentFrame)
{
return this
.Where(m => m.Frame <= currentFrame)
.OrderBy(m => m.Frame)
.LastOrDefault();
int lowerBoundIndex = this.LowerBoundBinarySearch(static m => m.Frame, currentFrame);
return lowerBoundIndex < 0 ? null : this[lowerBoundIndex];
}
public TasMovieMarker Next(int currentFrame)