From 67131caef3bc1c51b25f81de4b77b65af512e3fe Mon Sep 17 00:00:00 2001 From: jduncanator Date: Thu, 6 Sep 2018 11:25:26 +1000 Subject: [PATCH] Audio: Use built-in Unsafe.SizeOf() Built-in `SizeOf()` is 10x faster than our `TypeSize` helper. This also helps reduce code surface area. --- Ryujinx.Audio/Helpers/TypeSize.cs | 27 ------------------- .../Renderers/SoundIo/SoundIoAudioTrack.cs | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) delete mode 100644 Ryujinx.Audio/Helpers/TypeSize.cs diff --git a/Ryujinx.Audio/Helpers/TypeSize.cs b/Ryujinx.Audio/Helpers/TypeSize.cs deleted file mode 100644 index 5f041fb865..0000000000 --- a/Ryujinx.Audio/Helpers/TypeSize.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Reflection.Emit; - -namespace Ryujinx.Audio -{ - /// - /// Helper to determine the byte size of type - /// - public static class TypeSize - { - /// - /// The byte size of type - /// - public readonly static int Size; - - static TypeSize() - { - var dm = new DynamicMethod("", typeof(int), Type.EmptyTypes); - var il = dm.GetILGenerator(); - - il.Emit(OpCodes.Sizeof, typeof(T)); - il.Emit(OpCodes.Ret); - - Size = (int)dm.Invoke(null, null); - } - } -} diff --git a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs index 61e918f661..de354a7b23 100644 --- a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs +++ b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioTrack.cs @@ -495,7 +495,7 @@ namespace Ryujinx.Audio.SoundIo return; // Calculate the size of the audio samples - var size = TypeSize.Size; + var size = Unsafe.SizeOf(); // Calculate the amount of bytes to copy from the buffer var bytesToCopy = size * buffer.Length;