Audio: Use built-in Unsafe.SizeOf<T>()

Built-in `SizeOf<T>()` is 10x faster than our `TypeSize<T>` helper. This also helps reduce code surface area.
This commit is contained in:
jduncanator 2018-09-06 11:25:26 +10:00
parent a3944b4603
commit 67131caef3
2 changed files with 1 additions and 28 deletions

View file

@ -1,27 +0,0 @@
using System;
using System.Reflection.Emit;
namespace Ryujinx.Audio
{
/// <summary>
/// Helper to determine the byte size of type <see cref="T"/>
/// </summary>
public static class TypeSize<T>
{
/// <summary>
/// The byte size of type <see cref="T"/>
/// </summary>
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);
}
}
}

View file

@ -495,7 +495,7 @@ namespace Ryujinx.Audio.SoundIo
return;
// Calculate the size of the audio samples
var size = TypeSize<T>.Size;
var size = Unsafe.SizeOf<T>();
// Calculate the amount of bytes to copy from the buffer
var bytesToCopy = size * buffer.Length;