Performance improvement - removed unneeded case. We never hit it in our benchmarks or tests. We'll use Memory<T> instead of Span<T> again, where applicable.
This commit is contained in:
1 parent
06ef3d4fa4
commit
1b3c24bf74
2 files changed
+2
-43
No files matched your search
@@ -21,18 +21,14 @@ namespace Recyclable.Collections
|
|||||||
{
|
{
|
||||||
ArrayPool<T> arrayPool = _arrayPool;
|
ArrayPool<T> arrayPool = _arrayPool;
|
||||||
var sourceLength = source?.Length ?? 0;
|
var sourceLength = source?.Length ?? 0;
|
||||||
Span<T> sourceSpan, newArraySpan;
|
|
||||||
T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength
|
T[] newMemoryBlock = newSize >= RecyclableDefaults.MinPooledArrayLength
|
||||||
? arrayPool.Rent(newSize)
|
? arrayPool.Rent(newSize)
|
||||||
: new T[newSize];
|
: new T[newSize];
|
||||||
|
|
||||||
switch (newSize >= sourceLength)
|
|
||||||
{
|
|
||||||
case true:
|
|
||||||
if (sourceLength > 0)
|
if (sourceLength > 0)
|
||||||
{
|
{
|
||||||
sourceSpan = new Span<T>(source);
|
var sourceSpan = new Memory<T>(source);
|
||||||
newArraySpan = new Span<T>(newMemoryBlock);
|
var newArraySpan = new Memory<T>(newMemoryBlock);
|
||||||
sourceSpan.CopyTo(newArraySpan);
|
sourceSpan.CopyTo(newArraySpan);
|
||||||
if (sourceLength >= RecyclableDefaults.MinPooledArrayLength)
|
if (sourceLength >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
{
|
{
|
||||||
@@ -41,18 +37,6 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
return newMemoryBlock;
|
return newMemoryBlock;
|
||||||
|
|
||||||
case false:
|
|
||||||
sourceSpan = new Span<T>(source)[..newSize];
|
|
||||||
newArraySpan = new(newMemoryBlock);
|
|
||||||
sourceSpan.CopyTo(newArraySpan);
|
|
||||||
if (sourceLength >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
|
||||||
arrayPool.Return(source!);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newMemoryBlock;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int EnsureCapacity(in int requestedCapacity)
|
protected int EnsureCapacity(in int requestedCapacity)
|
||||||
|
|||||||
@@ -88,9 +88,6 @@ namespace Recyclable.Collections
|
|||||||
? arrayPool.Rent(requiredBlockCount)
|
? arrayPool.Rent(requiredBlockCount)
|
||||||
: new T[requiredBlockCount][];
|
: new T[requiredBlockCount][];
|
||||||
|
|
||||||
switch (requiredBlockCount >= sourceBlockCount)
|
|
||||||
{
|
|
||||||
case true:
|
|
||||||
switch (sourceBlockCount > 0)
|
switch (sourceBlockCount > 0)
|
||||||
{
|
{
|
||||||
case true:
|
case true:
|
||||||
@@ -149,28 +146,6 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
return newMemoryBlocks;
|
return newMemoryBlocks;
|
||||||
|
|
||||||
case false:
|
|
||||||
sourceSpan = new Span<T[]>(source)[..requiredBlockCount];
|
|
||||||
newArraySpan = new Span<T[]>(newMemoryBlocks);
|
|
||||||
sourceSpan.CopyTo(newArraySpan);
|
|
||||||
sourceSpan = new Span<T[]>(source)[newArraySpan.Length..];
|
|
||||||
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!);
|
|
||||||
}
|
|
||||||
|
|
||||||
return newMemoryBlocks;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long EnsureCapacity(in long requestedCapacity)
|
protected long EnsureCapacity(in long requestedCapacity)
|
||||||
|
|||||||
Reference in new issue
Block a user