IF's inverted to match expected most frequent scenarios.

This commit is contained in:
mlemanczyk committed 2023-01-29 14:20:59 +01:00
1 parent 6270f79291
commit a3335bf4e7
1 file changed
+10 -10
+10 -10
View File
@@ -45,14 +45,14 @@ namespace Recyclable.Collections
} }
list._longCount--; list._longCount--;
if (list._lastItemIndex <= 0) if (list._lastItemIndex > 0)
{ {
list._lastBlockIndex--; list._lastItemIndex--;
list._lastItemIndex = list._blockSize;
} }
else else
{ {
list._lastItemIndex--; list._lastBlockIndex--;
list._lastItemIndex = list._blockSize;
} }
int blockSize = list._blockSize; int blockSize = list._blockSize;
@@ -80,9 +80,9 @@ namespace Recyclable.Collections
var sourceBlockCount = source?.Length ?? 0; var sourceBlockCount = source?.Length ?? 0;
int requiredBlockCount = (int)(newCapacity / blockSize) + (newCapacity % blockSize > 0 ? 1 : 0); int requiredBlockCount = (int)(newCapacity / blockSize) + (newCapacity % blockSize > 0 ? 1 : 0);
T[][] newMemoryBlocks = requiredBlockCount >= RecyclableDefaults.MinPooledArrayLength T[][] newMemoryBlocks = requiredBlockCount < RecyclableDefaults.MinPooledArrayLength
? arrayPool.Rent(requiredBlockCount) ? new T[requiredBlockCount][]
: new T[requiredBlockCount][]; : arrayPool.Rent(requiredBlockCount);
var newMemoryBlocksSpan = new Span<T[]>(newMemoryBlocks); var newMemoryBlocksSpan = new Span<T[]>(newMemoryBlocks);
if (sourceBlockCount > 0) if (sourceBlockCount > 0)
@@ -500,13 +500,13 @@ namespace Recyclable.Collections
public bool Remove(T item) => throw new NotSupportedException(); public bool Remove(T item) => throw new NotSupportedException();
public void RemoveBlock(int index) public void RemoveBlock(int index)
{ {
if (_blockSize >= RecyclableDefaults.MinPooledArrayLength) if (_blockSize < RecyclableDefaults.MinPooledArrayLength)
{ {
_blockArrayPool.Return(_memoryBlocks[index]); _memoryBlocks[index] = _emptyBlockArray;
} }
else else
{ {
_memoryBlocks[index] = _emptyBlockArray; _blockArrayPool.Return(_memoryBlocks[index]);
} }
_capacity -= _blockSize; _capacity -= _blockSize;