Skip to content

Commit

Permalink
performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
koliva8245 committed Jun 27, 2024
1 parent 95748e6 commit 9a26d9c
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Heroes.MpqTool/BZip2/BZip2InputStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,16 +425,15 @@ private static void HbCreateDecodeTables(int[] limit, int[] bbase, int[] perm, c
}
}

private void MakeMaps()
private void MakeMaps(Span<bool> inUseSpan)
{
bool[] inUse = _data!.InUse;
byte[] seqToUnseq = _data.SeqToUnseq;
byte[] seqToUnseq = _data!.SeqToUnseq;

int n = 0;

for (int i = 0; i < 256; i++)
{
if (inUse[i])
if (inUseSpan[i])
seqToUnseq[n++] = (byte)i;
}

Expand Down Expand Up @@ -596,7 +595,6 @@ private uint BsGetInt()
private void RecvDecodingTables()
{
DecompressionState s = _data!;
bool[] inUse = s.InUse;
byte[] pos = s.RecvDecodingTables_pos;

int inUse16 = 0;
Expand All @@ -610,9 +608,11 @@ private void RecvDecodingTables()
}
}

Span<bool> inUseSpan = stackalloc bool[256];

for (int i = 256; --i >= 0;)
{
inUse[i] = false;
inUseSpan[i] = false;
}

for (int i = 0; i < 16; i++)
Expand All @@ -624,13 +624,13 @@ private void RecvDecodingTables()
{
if (BsGetBit())
{
inUse[i16 + j] = true;
inUseSpan[i16 + j] = true;
}
}
}
}

MakeMaps();
MakeMaps(inUseSpan);
int alphaSize = _nInUse + 2;

/* Now the selectors */
Expand Down Expand Up @@ -1230,9 +1230,6 @@ public DecompressionState(int blockSize100k)
Ll8List = new();
}

// (with blockSize 900k)
public bool[] InUse { get; } = new bool[256];

public byte[] SeqToUnseq { get; } = new byte[256]; // 256 byte

public List<byte> SelectorList { get; } = new();
Expand All @@ -1257,7 +1254,7 @@ public DecompressionState(int blockSize100k)

public byte[] RecvDecodingTables_pos { get; }

public int[]? Tt { get; private set; } // 3600000 byte
public int[]? Tt { get; private set; }

public List<byte> Ll8List { get; }

Expand Down

0 comments on commit 9a26d9c

Please sign in to comment.