Micro improvements to get even a bit smaller code size.
This commit is contained in:
1 parent
68582f0ffd
commit
b9a0589597
2 files changed
+6
-6
No files matched your search
@@ -211,13 +211,13 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public bool Contains(T item) => _count > 0 && Array.IndexOf(_memoryBlock, item, 0, _count) >= 0;
|
public bool Contains(T item) => _count != 0 && Array.IndexOf(_memoryBlock, item, 0, _count) >= 0;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
public void CopyTo(T[] array, int index) => Array.Copy(_memoryBlock, 0, array, index, _count);
|
public void CopyTo(T[] array, int index) => Array.Copy(_memoryBlock, 0, array, index, _count);
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public int IndexOf(T itemToFind) => _count > 0 ? Array.IndexOf(_memoryBlock, itemToFind, 0, _count) : RecyclableDefaults.ItemNotFoundIndex;
|
public int IndexOf(T itemToFind) => _count != 0 ? Array.IndexOf(_memoryBlock, itemToFind, 0, _count) : RecyclableDefaults.ItemNotFoundIndex;
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public void Insert(int index, T item)
|
public void Insert(int index, T item)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ namespace Recyclable.Collections
|
|||||||
Span<T> sourceBlockMemory;
|
Span<T> sourceBlockMemory;
|
||||||
Span<T> destinationArrayMemory;
|
Span<T> destinationArrayMemory;
|
||||||
int startingBlockIndex = (int)(startingIndex / blockSize);
|
int startingBlockIndex = (int)(startingIndex / blockSize);
|
||||||
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize > 0 ? 1 : 0)) - 1;
|
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize != 0 ? 1 : 0)) - 1;
|
||||||
Span<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
Span<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
||||||
destinationArrayMemory = new Span<T>(destinationArray, destinationArrayIndex, (int)Math.Min(destinationArray.Length - destinationArrayIndex, itemsCount));
|
destinationArrayMemory = new Span<T>(destinationArray, destinationArrayIndex, (int)Math.Min(destinationArray.Length - destinationArrayIndex, itemsCount));
|
||||||
int memoryBlockIndex;
|
int memoryBlockIndex;
|
||||||
@@ -90,7 +90,7 @@ namespace Recyclable.Collections
|
|||||||
destinationArrayMemory = destinationArrayMemory[blockSize..];
|
destinationArrayMemory = destinationArrayMemory[blockSize..];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (itemsCount - (lastBlockIndex * blockSize) > 0)
|
if (itemsCount - (lastBlockIndex * blockSize) != 0)
|
||||||
{
|
{
|
||||||
sourceBlockMemory = new(sourceMemoryBlocksSpan[lastBlockIndex], 0, (int)(itemsCount - (lastBlockIndex * blockSize)));
|
sourceBlockMemory = new(sourceMemoryBlocksSpan[lastBlockIndex], 0, (int)(itemsCount - (lastBlockIndex * blockSize)));
|
||||||
sourceBlockMemory.CopyTo(destinationArrayMemory);
|
sourceBlockMemory.CopyTo(destinationArrayMemory);
|
||||||
@@ -105,7 +105,7 @@ namespace Recyclable.Collections
|
|||||||
}
|
}
|
||||||
|
|
||||||
int startingBlockIndex = (int)(startingIndex / blockSize);
|
int startingBlockIndex = (int)(startingIndex / blockSize);
|
||||||
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize > 0 ? 1 : 0)) - 1;
|
int lastBlockIndex = (int)((itemsCount / blockSize) + (itemsCount % blockSize != 0 ? 1 : 0)) - 1;
|
||||||
|
|
||||||
var destinationIndex = destinationArrayIndex;
|
var destinationIndex = destinationArrayIndex;
|
||||||
Span<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
Span<T[]> sourceMemoryBlocksSpan = new(sourceMemoryBlocks, startingBlockIndex, lastBlockIndex + 1);
|
||||||
@@ -143,7 +143,7 @@ namespace Recyclable.Collections
|
|||||||
public static long Resize(RecyclableLongList<T> list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity)
|
public static long Resize(RecyclableLongList<T> list, int minBlockSize, byte minBlockSizePow2Shift, long newCapacity)
|
||||||
{
|
{
|
||||||
int sourceBlockCount = list._memoryBlocks?.Length ?? 0;
|
int sourceBlockCount = list._memoryBlocks?.Length ?? 0;
|
||||||
int requiredBlockCount = checked((int)(newCapacity >> minBlockSizePow2Shift) + ((newCapacity & (minBlockSize - 1)) > 0 ? 1 : 0));
|
int requiredBlockCount = checked((int)(newCapacity >> minBlockSizePow2Shift) + ((newCapacity & (minBlockSize - 1)) != 0 ? 1 : 0));
|
||||||
int blockIndex;
|
int blockIndex;
|
||||||
|
|
||||||
T[][] newMemoryBlocks;
|
T[][] newMemoryBlocks;
|
||||||
|
|||||||
Reference in new issue
Block a user