From 7ab2ca6b89c7a375699204404c58d1e40e6d7df6 Mon Sep 17 00:00:00 2001 From: Morilli <35152647+Morilli@users.noreply.github.com> Date: Sun, 20 Oct 2024 14:00:11 +0200 Subject: [PATCH] Add SequenceEqual extension to prevent linq usage this speeds up the state history integrity check by about an order of magnitude --- src/BizHawk.Bizware.Graphics/BitmapBuffer.cs | 10 ++++------ src/BizHawk.Common/Extensions/CollectionExtensions.cs | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs index 0352fb45028..2be7ce71123 100644 --- a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs +++ b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs @@ -8,6 +8,8 @@ using System.IO; using System.Runtime.InteropServices; +using BizHawk.Common.CollectionExtensions; + using SDGraphics = System.Drawing.Graphics; namespace BizHawk.Bizware.Graphics @@ -34,10 +36,6 @@ public unsafe class BitmapBuffer : IDisposable private GCHandle CurrLockHandle; private BitmapData CurrLock; - /// same as (A8R8G8B8) - public Span AsSpan() - => Pixels; - /// already locked /// TODO add read/write semantic, for wraps public BitmapData LockBits() @@ -545,7 +543,7 @@ private static int NextHigher(int k) } 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); /// /// Dumps this BitmapBuffer to a new System.Drawing.Bitmap @@ -607,4 +605,4 @@ public void ToSysdrawingBitmap(Bitmap bmp) } -} \ No newline at end of file +} diff --git a/src/BizHawk.Common/Extensions/CollectionExtensions.cs b/src/BizHawk.Common/Extensions/CollectionExtensions.cs index a016528466f..1ec74fe9675 100644 --- a/src/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/src/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -321,5 +321,7 @@ public static bool IsSortedDesc(this ReadOnlySpan span) 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(this T[] a, ReadOnlySpan b) where T : IEquatable => a.AsSpan().SequenceEqual(b); } }