Use spans to improve performance in StreamExts.

Also avoid ReadBytes calls that allocate a buffer by either updating the stream position (if not interested in the bytes), by reusing an input buffer (if interested in the bytes), or using a stackalloc buffer to avoid the allocation (for small reads).
This commit is contained in:
RoosterDragon
2023-09-19 18:10:09 +01:00
committed by Gustas
parent b3ee3551ca
commit 5d91b678bb
20 changed files with 153 additions and 92 deletions

View File

@@ -20,11 +20,11 @@ namespace OpenRA.Mods.Common.FileFormats
static readonly int[] AudWsStepTable2 = { -2, -1, 0, 1 };
static readonly int[] AudWsStepTable4 = { -9, -8, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 8 };
public static void DecodeWestwoodCompressedSample(byte[] input, byte[] output)
public static void DecodeWestwoodCompressedSample(ReadOnlySpan<byte> input, Span<byte> output)
{
if (input.Length == output.Length)
{
Array.Copy(input, output, output.Length);
input.CopyTo(output);
return;
}