Add SequenceEqual extension to prevent linq usage

this speeds up the state history integrity check by about an order of magnitude
This commit is contained in:
Morilli 2024-10-20 14:00:11 +02:00
parent 1dbd7356eb
commit 7ab2ca6b89
2 changed files with 6 additions and 6 deletions

View File

@ -8,6 +8,8 @@ using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using BizHawk.Common.CollectionExtensions;
using SDGraphics = System.Drawing.Graphics;
namespace BizHawk.Bizware.Graphics
@ -34,10 +36,6 @@ namespace BizHawk.Bizware.Graphics
private GCHandle CurrLockHandle;
private BitmapData CurrLock;
/// <summary>same as <see cref="Pixels"/> (<see cref="PixelFormat.Format32bppArgb">A8R8G8B8</see>)</summary>
public Span<int> AsSpan()
=> Pixels;
/// <exception cref="InvalidOperationException">already locked</exception>
/// <remarks>TODO add read/write semantic, for wraps</remarks>
public BitmapData LockBits()
@ -545,7 +543,7 @@ namespace BizHawk.Bizware.Graphics
}
public bool SequenceEqual(BitmapBuffer other)
=> Width == other.Width && Height == other.Height && AsSpan().SequenceEqual(other.AsSpan());
=> Width == other.Width && Height == other.Height && Pixels.SequenceEqual(other.Pixels);
/// <summary>
/// Dumps this BitmapBuffer to a new System.Drawing.Bitmap
@ -607,4 +605,4 @@ namespace BizHawk.Bizware.Graphics
}
}
}

View File

@ -321,5 +321,7 @@ namespace BizHawk.Common.CollectionExtensions
for (int i = 0, e = span.Length - 1; i < e; i++) if (span[i + 1].CompareTo(span[i]) > 0) return false;
return true;
}
public static bool SequenceEqual<T>(this T[] a, ReadOnlySpan<T> b) where T : IEquatable<T> => a.AsSpan().SequenceEqual(b);
}
}