Performance improvement - removed unneeded case. We never hit it in our benchmarks or tests.
This commit is contained in:
1 parent
06ef3d4fa4
commit
8b7c4407d5
1 file changed
+49
-74
@@ -88,89 +88,64 @@ namespace Recyclable.Collections
|
|||||||
? arrayPool.Rent(requiredBlockCount)
|
? arrayPool.Rent(requiredBlockCount)
|
||||||
: new T[requiredBlockCount][];
|
: new T[requiredBlockCount][];
|
||||||
|
|
||||||
switch (requiredBlockCount >= sourceBlockCount)
|
switch (sourceBlockCount > 0)
|
||||||
{
|
{
|
||||||
case true:
|
case true:
|
||||||
switch (sourceBlockCount > 0)
|
sourceSpan = new Span<T[]>(source);
|
||||||
{
|
|
||||||
case true:
|
|
||||||
sourceSpan = new Span<T[]>(source);
|
|
||||||
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
|
||||||
sourceSpan.CopyTo(newArraySpan);
|
|
||||||
if (sourceSpan.Length >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
|
||||||
arrayPool.Return(source!);
|
|
||||||
}
|
|
||||||
|
|
||||||
newArraySpan = newArraySpan[sourceBlockCount..];
|
|
||||||
break;
|
|
||||||
|
|
||||||
case false:
|
|
||||||
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
int uninitializedBlocksCount = newArraySpan.Length;
|
|
||||||
if (uninitializedBlocksCount == requiredBlockCount)
|
|
||||||
{
|
|
||||||
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
|
||||||
case true:
|
|
||||||
newArraySpan[0] = blockArrayPool.Rent(blockSize);
|
|
||||||
blockSize = newArraySpan[0].Length;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case false:
|
|
||||||
newArraySpan[0] = new T[blockSize];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
newArraySpan = newArraySpan[1..];
|
|
||||||
uninitializedBlocksCount--;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
|
||||||
case true:
|
|
||||||
for (int i = 0; i < uninitializedBlocksCount; i++)
|
|
||||||
{
|
|
||||||
newArraySpan[i] = blockArrayPool.Rent(blockSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case false:
|
|
||||||
for (int i = 0; i < uninitializedBlocksCount; i++)
|
|
||||||
{
|
|
||||||
newArraySpan[i] = new T[blockSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newMemoryBlocks;
|
|
||||||
|
|
||||||
case false:
|
|
||||||
sourceSpan = new Span<T[]>(source)[..requiredBlockCount];
|
|
||||||
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
||||||
sourceSpan.CopyTo(newArraySpan);
|
sourceSpan.CopyTo(newArraySpan);
|
||||||
sourceSpan = new Span<T[]>(source)[newArraySpan.Length..];
|
if (sourceSpan.Length >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
int sourceLength = sourceSpan.Length;
|
|
||||||
if (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < sourceLength; i++)
|
|
||||||
{
|
|
||||||
blockArrayPool.Return(sourceSpan[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sourceLength >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
{
|
||||||
arrayPool.Return(source!);
|
arrayPool.Return(source!);
|
||||||
}
|
}
|
||||||
|
|
||||||
return newMemoryBlocks;
|
newArraySpan = newArraySpan[sourceBlockCount..];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case false:
|
||||||
|
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int uninitializedBlocksCount = newArraySpan.Length;
|
||||||
|
if (uninitializedBlocksCount == requiredBlockCount)
|
||||||
|
{
|
||||||
|
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
newArraySpan[0] = blockArrayPool.Rent(blockSize);
|
||||||
|
blockSize = newArraySpan[0].Length;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case false:
|
||||||
|
newArraySpan[0] = new T[blockSize];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
newArraySpan = newArraySpan[1..];
|
||||||
|
uninitializedBlocksCount--;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
for (int i = 0; i < uninitializedBlocksCount; i++)
|
||||||
|
{
|
||||||
|
newArraySpan[i] = blockArrayPool.Rent(blockSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case false:
|
||||||
|
for (int i = 0; i < uninitializedBlocksCount; i++)
|
||||||
|
{
|
||||||
|
newArraySpan[i] = new T[blockSize];
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return newMemoryBlocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long EnsureCapacity(in long requestedCapacity)
|
protected long EnsureCapacity(in long requestedCapacity)
|
||||||
|
|||||||
Reference in new issue
Block a user