Switches converted back to IFs. They are IF's in IL anyway.
This commit is contained in:
1 parent
16acdff58a
commit
6270f79291
1 file changed
+68
-85
@@ -45,16 +45,14 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
list._longCount--;
|
list._longCount--;
|
||||||
switch (list._lastItemIndex)
|
if (list._lastItemIndex <= 0)
|
||||||
{
|
{
|
||||||
case 0:
|
list._lastBlockIndex--;
|
||||||
list._lastBlockIndex--;
|
list._lastItemIndex = list._blockSize;
|
||||||
list._lastItemIndex = list._blockSize;
|
}
|
||||||
break;
|
else
|
||||||
|
{
|
||||||
default:
|
list._lastItemIndex--;
|
||||||
list._lastItemIndex--;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int blockSize = list._blockSize;
|
int blockSize = list._blockSize;
|
||||||
@@ -103,39 +101,33 @@ namespace Recyclable.Collections
|
|||||||
int uninitializedBlocksCount = newMemoryBlocksSpan.Length;
|
int uninitializedBlocksCount = newMemoryBlocksSpan.Length;
|
||||||
if (uninitializedBlocksCount == requiredBlockCount)
|
if (uninitializedBlocksCount == requiredBlockCount)
|
||||||
{
|
{
|
||||||
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
if (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
{
|
{
|
||||||
case true:
|
newMemoryBlocksSpan[0] = blockArrayPool.Rent(blockSize);
|
||||||
newMemoryBlocksSpan[0] = blockArrayPool.Rent(blockSize);
|
blockSize = newMemoryBlocksSpan[0].Length;
|
||||||
blockSize = newMemoryBlocksSpan[0].Length;
|
}
|
||||||
break;
|
else
|
||||||
|
{
|
||||||
case false:
|
newMemoryBlocksSpan[0] = new T[blockSize];
|
||||||
newMemoryBlocksSpan[0] = new T[blockSize];
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newMemoryBlocksSpan = newMemoryBlocksSpan[1..];
|
newMemoryBlocksSpan = newMemoryBlocksSpan[1..];
|
||||||
uninitializedBlocksCount--;
|
uninitializedBlocksCount--;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
if (blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
{
|
{
|
||||||
case true:
|
for (int i = 0; i < uninitializedBlocksCount; i++)
|
||||||
for (int i = 0; i < uninitializedBlocksCount; i++)
|
{
|
||||||
{
|
newMemoryBlocksSpan[i] = blockArrayPool.Rent(blockSize);
|
||||||
newMemoryBlocksSpan[i] = blockArrayPool.Rent(blockSize);
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
break;
|
{
|
||||||
|
for (int i = 0; i < uninitializedBlocksCount; i++)
|
||||||
case false:
|
{
|
||||||
for (int i = 0; i < uninitializedBlocksCount; i++)
|
newMemoryBlocksSpan[i] = new T[blockSize];
|
||||||
{
|
}
|
||||||
newMemoryBlocksSpan[i] = new T[blockSize];
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return newMemoryBlocks;
|
return newMemoryBlocks;
|
||||||
@@ -146,20 +138,17 @@ namespace Recyclable.Collections
|
|||||||
T[][] memory = _memoryBlocks;
|
T[][] memory = _memoryBlocks;
|
||||||
long newCapacity;
|
long newCapacity;
|
||||||
|
|
||||||
switch (_capacity > 0)
|
if (_capacity > 0)
|
||||||
{
|
{
|
||||||
case true:
|
newCapacity = _capacity;
|
||||||
newCapacity = _capacity;
|
while (newCapacity < requestedCapacity)
|
||||||
while (newCapacity < requestedCapacity)
|
{
|
||||||
{
|
newCapacity *= 2;
|
||||||
newCapacity *= 2;
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
break;
|
{
|
||||||
|
newCapacity = requestedCapacity;
|
||||||
case false:
|
|
||||||
newCapacity = requestedCapacity;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
memory = SetNewLength(memory, _blockSize, newCapacity);
|
memory = SetNewLength(memory, _blockSize, newCapacity);
|
||||||
@@ -176,45 +165,41 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
public RecyclableList(int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
public RecyclableList(int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
||||||
{
|
{
|
||||||
switch (expectedItemsCount > 0)
|
if (expectedItemsCount > 0)
|
||||||
{
|
{
|
||||||
case true:
|
_memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value);
|
||||||
_memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value);
|
if (_memoryBlocks.Length > 0)
|
||||||
if (_memoryBlocks.Length > 0)
|
{
|
||||||
{
|
blockSize = _memoryBlocks[0].Length;
|
||||||
blockSize = _memoryBlocks[0].Length;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_blockSize = blockSize;
|
_blockSize = blockSize;
|
||||||
_capacity = _memoryBlocks.Length * blockSize;
|
_capacity = _memoryBlocks.Length * blockSize;
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
case false:
|
{
|
||||||
_blockSize = blockSize;
|
_blockSize = blockSize;
|
||||||
_memoryBlocks = _emptyMemoryBlocksArray;
|
_memoryBlocks = _emptyMemoryBlocksArray;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RecyclableList(IEnumerable<T> source, int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
public RecyclableList(IEnumerable<T> source, int blockSize = RecyclableDefaults.BlockSize, long? expectedItemsCount = default)
|
||||||
{
|
{
|
||||||
switch (expectedItemsCount > 0)
|
if (expectedItemsCount > 0)
|
||||||
{
|
{
|
||||||
case true:
|
_memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value);
|
||||||
_memoryBlocks = SetNewLength(_memoryBlocks, blockSize, expectedItemsCount.Value);
|
if (_memoryBlocks.Length > 0)
|
||||||
if (_memoryBlocks.Length > 0)
|
{
|
||||||
{
|
blockSize = _memoryBlocks[0].Length;
|
||||||
blockSize = _memoryBlocks[0].Length;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_blockSize = blockSize;
|
_blockSize = blockSize;
|
||||||
_capacity = _memoryBlocks.Length * blockSize;
|
_capacity = _memoryBlocks.Length * blockSize;
|
||||||
break;
|
}
|
||||||
|
else
|
||||||
case false:
|
{
|
||||||
_blockSize = blockSize;
|
_blockSize = blockSize;
|
||||||
_memoryBlocks = _emptyMemoryBlocksArray;
|
_memoryBlocks = _emptyMemoryBlocksArray;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AddRange(source);
|
AddRange(source);
|
||||||
@@ -515,15 +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)
|
||||||
{
|
{
|
||||||
switch (_blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
if (_blockSize >= RecyclableDefaults.MinPooledArrayLength)
|
||||||
{
|
{
|
||||||
case true:
|
_blockArrayPool.Return(_memoryBlocks[index]);
|
||||||
_blockArrayPool.Return(_memoryBlocks[index]);
|
}
|
||||||
break;
|
else
|
||||||
|
{
|
||||||
case false:
|
_memoryBlocks[index] = _emptyBlockArray;
|
||||||
_memoryBlocks[index] = _emptyBlockArray;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_capacity -= _blockSize;
|
_capacity -= _blockSize;
|
||||||
|
|||||||
Reference in new issue
Block a user