fix: Fixes STArray size and tests (#1737)

This commit is contained in:
Kamron Batman 2024-04-23 16:18:24 -07:00 committed by GitHub
parent 3a27ab8810
commit 7a160bb0fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View file

@ -36,12 +36,11 @@ public class STArrayPoolTests
{
STArrayPool<byte>.Shared.ResetForTesting();
var cores = Environment.ProcessorCount;
var arrays1 = new byte[cores * 8 + 2][]; // 1 for the cache, and 8 * CPU for the stacks
var weakReferences1 = new WeakReference[cores * 8 + 2];
var arrays1 = new byte[32 + 2][]; // 1 for the cache, 32 for the cores, and 1 for overflow
var weakReferences1 = new WeakReference[32 + 2];
var arrays2 = new byte[cores * 8 + 2][]; // 1 for the cache, and 8 * CPU for the stacks
var weakReferences2 = new WeakReference[cores * 8 + 2];
var arrays2 = new byte[32 + 2][];
var weakReferences2 = new WeakReference[32 + 2];
for (var i = 0; i < arrays1.Length; i++)
{

View file

@ -62,7 +62,7 @@ public class STArrayPool<T> : ArrayPool<T>
if (minimumLength == 0)
{
// We aren't renting.
return Array.Empty<T>();
return [];
}
if (minimumLength < 0)
@ -74,7 +74,7 @@ public class STArrayPool<T> : ArrayPool<T>
return buffer;
}
public override void Return(T[] array, bool clearArray = false)
public override void Return(T[]? array, bool clearArray = false)
{
if (array is null)
{
@ -231,7 +231,7 @@ public class STArrayPool<T> : ArrayPool<T>
private sealed class STArrayStack
{
// Maximum buffers we will store in our stack
private readonly T[][] _arrays = new T[StackArraySize * Environment.ProcessorCount][];
private readonly T[][] _arrays = new T[StackArraySize][];
private int _count;
private long _ticks;