More LZMA fixes?

This commit is contained in:
Adam Hathcock
2026-01-26 15:50:50 +00:00
parent 979c8d9234
commit 27cf2795ef
2 changed files with 22 additions and 2 deletions

View File

@@ -114,6 +114,8 @@ internal partial class Decoder
_total = 5;
}
public void ReleaseStream() => _stream = null;
public async ValueTask NormalizeAsync(CancellationToken cancellationToken = default)
{
while (_range < K_TOP_VALUE)
@@ -132,6 +134,24 @@ internal partial class Decoder
}
}
public async ValueTask Normalize2Async(CancellationToken cancellationToken = default)
{
if (_range < K_TOP_VALUE)
{
var buffer = new byte[1];
var read = await _stream
.ReadAsync(buffer, 0, 1, cancellationToken)
.ConfigureAwait(false);
if (read == 0)
{
throw new EndOfStreamException();
}
_code = (_code << 8) | buffer[0];
_range <<= 8;
_total++;
}
}
public async ValueTask<uint> DecodeDirectBitsAsync(
int numTotalBits,
CancellationToken cancellationToken = default

View File

@@ -45,13 +45,13 @@ internal partial struct BitDecoder
{
decoder._range = newBound;
_prob += (K_BIT_MODEL_TOTAL - _prob) >> K_NUM_MOVE_BITS;
await decoder.NormalizeAsync(cancellationToken).ConfigureAwait(false);
await decoder.Normalize2Async(cancellationToken).ConfigureAwait(false);
return 0;
}
decoder._range -= newBound;
decoder._code -= newBound;
_prob -= (_prob) >> K_NUM_MOVE_BITS;
await decoder.NormalizeAsync(cancellationToken).ConfigureAwait(false);
await decoder.Normalize2Async(cancellationToken).ConfigureAwait(false);
return 1;
}
}