stackalloc readtables

This commit is contained in:
majorro
2025-01-13 23:28:26 +03:00
parent a070493fba
commit 91364c6a7c
3 changed files with 8 additions and 11 deletions

View File

@@ -866,9 +866,9 @@ internal sealed partial class Unpack : BitInput, IRarUnpack, IDisposable
private bool ReadTables()
{
var bitLength = new byte[PackDef.BC];
Span<byte> bitLength = stackalloc byte[PackDef.BC];
Span<byte> table = stackalloc byte[PackDef.HUFF_TABLE_SIZE];
var table = new byte[PackDef.HUFF_TABLE_SIZE];
if (inAddr > readTop - 25)
{
if (!unpReadBuf())
@@ -996,7 +996,7 @@ internal sealed partial class Unpack : BitInput, IRarUnpack, IDisposable
// memcpy(unpOldTable,table,sizeof(unpOldTable));
Buffer.BlockCopy(table, 0, unpOldTable, 0, unpOldTable.Length);
table.CopyTo(unpOldTable);
return (true);
}

View File

@@ -391,11 +391,9 @@ internal partial class Unpack
private bool ReadTables20()
{
var BitLength = new byte[PackDef.BC20];
var Table = new byte[PackDef.MC20 * 4];
int TableSize,
N,
I;
Span<byte> BitLength = stackalloc byte[PackDef.BC20];
Span<byte> Table = stackalloc byte[PackDef.MC20 * 4];
int TableSize, N, I;
if (inAddr > readTop - 25)
{
if (!unpReadBuf())

View File

@@ -181,13 +181,12 @@ internal static class UnpackUtility
return (dec.DecodeNum[N]);
}
internal static void makeDecodeTables(byte[] lenTab, int offset, Decode.Decode dec, int size)
internal static void makeDecodeTables(Span<byte> lenTab, int offset, Decode.Decode dec, int size)
{
Span<int> lenCount = stackalloc int[16];
Span<int> tmpPos = stackalloc int[16];
int i;
long M,
N;
long M, N;
new Span<int>(dec.DecodeNum).Clear(); // memset(Dec->DecodeNum,0,Size*sizeof(*Dec->DecodeNum));