Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public static ZstandardDictionary Train(ReadOnlySpan<byte> samples, ReadOnlySpan
// This incidentally also protects against concurrent modifications of the sampleLengths that could cause
// access violations later in native code.
byte[] lengthsArray = ArrayPool<byte>.Shared.Rent(sampleLengths.Length * Unsafe.SizeOf<nuint>());
byte[]? dictionaryBuffer = null;
try
{
Span<nuint> lengthsAsNuint = MemoryMarshal.Cast<byte, nuint>(lengthsArray.AsSpan(0, sampleLengths.Length * Unsafe.SizeOf<nuint>()));
Expand All @@ -127,8 +128,7 @@ public static ZstandardDictionary Train(ReadOnlySpan<byte> samples, ReadOnlySpan

ArgumentOutOfRangeException.ThrowIfLessThan(maxDictionarySize, 256, nameof(maxDictionarySize));

byte[] dictionaryBuffer = new byte[maxDictionarySize];

dictionaryBuffer = ArrayPool<byte>.Shared.Rent(maxDictionarySize);
nuint dictSize;

unsafe
Expand All @@ -148,6 +148,10 @@ public static ZstandardDictionary Train(ReadOnlySpan<byte> samples, ReadOnlySpan
}
finally
{
if (dictionaryBuffer is not null)
{
ArrayPool<byte>.Shared.Return(dictionaryBuffer);
}
ArrayPool<byte>.Shared.Return(lengthsArray);
}
}
Expand Down
Loading