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:
parent
a3944b4603
commit
67131caef3
2 changed files with 1 additions and 28 deletions
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -495,7 +495,7 @@ namespace Ryujinx.Audio.SoundIo
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Calculate the size of the audio samples
|
// 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
|
// Calculate the amount of bytes to copy from the buffer
|
||||||
var bytesToCopy = size * buffer.Length;
|
var bytesToCopy = size * buffer.Length;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue