From 9acdcdbcf7f2b34f5f2fa100727f5ab90aa11411 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 21 Oct 2024 17:39:51 +1000 Subject: [PATCH] Restore `BitmapBuffer.AsSpan` and add `AggressiveInlining` fixes 9a5a75e5b and 7ab2ca6b8 --- src/BizHawk.Bizware.Graphics/BitmapBuffer.cs | 10 ++++++++-- src/BizHawk.Common/Extensions/CollectionExtensions.cs | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs index 2be7ce7112..104822086e 100644 --- a/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs +++ b/src/BizHawk.Bizware.Graphics/BitmapBuffer.cs @@ -6,6 +6,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using BizHawk.Common.CollectionExtensions; @@ -36,6 +37,11 @@ namespace BizHawk.Bizware.Graphics private GCHandle CurrLockHandle; private BitmapData CurrLock; + /// same as (A8R8G8B8) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public Span AsSpan() + => Pixels; + /// already locked /// TODO add read/write semantic, for wraps public BitmapData LockBits() @@ -221,7 +227,7 @@ namespace BizHawk.Bizware.Graphics } public BitmapBuffer Copy() - => new(width: Width, height: Height, pixels: Pixels.AsSpan().ToArray()); + => new(width: Width, height: Height, pixels: AsSpan().ToArray()); /// TODO surely there's a better implementation --yoshi public BitmapBuffer Copy(Rectangle region) @@ -543,7 +549,7 @@ namespace BizHawk.Bizware.Graphics } public bool SequenceEqual(BitmapBuffer other) - => Width == other.Width && Height == other.Height && Pixels.SequenceEqual(other.Pixels); + => Width == other.Width/* && Height == other.Height*/ && AsSpan().SequenceEqual(other.AsSpan()); /// /// Dumps this BitmapBuffer to a new System.Drawing.Bitmap diff --git a/src/BizHawk.Common/Extensions/CollectionExtensions.cs b/src/BizHawk.Common/Extensions/CollectionExtensions.cs index 1ec74fe967..2dc9ea4e3f 100644 --- a/src/BizHawk.Common/Extensions/CollectionExtensions.cs +++ b/src/BizHawk.Common/Extensions/CollectionExtensions.cs @@ -322,6 +322,7 @@ namespace BizHawk.Common.CollectionExtensions return true; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool SequenceEqual(this T[] a, ReadOnlySpan b) where T : IEquatable => a.AsSpan().SequenceEqual(b); } }