Unnecessary arithmetic overflow checks removed.
This commit is contained in:
1 parent
c1326b8dea
commit
8aebac97b5
1 file changed
+6
-6
@@ -66,11 +66,11 @@ namespace Recyclable.Collections
|
|||||||
T[][] memoryBlocks = list._memoryBlocks;
|
T[][] memoryBlocks = list._memoryBlocks;
|
||||||
int nextItemIndex = list._nextItemIndex;
|
int nextItemIndex = list._nextItemIndex;
|
||||||
int blockSize = list._blockSize;
|
int blockSize = list._blockSize;
|
||||||
int sourceBlockIndex = checked((int)((index + 1) >> list._blockSizePow2BitShift));
|
int sourceBlockIndex = (int)((index + 1) >> list._blockSizePow2BitShift);
|
||||||
int sourceItemIndex = checked((int)((index + 1) & list._blockSizeMinus1));
|
int sourceItemIndex = (int)((index + 1) & list._blockSizeMinus1);
|
||||||
|
|
||||||
int targetBlockIndex = checked((int)(index >> list._blockSizePow2BitShift));
|
int targetBlockIndex = (int)(index >> list._blockSizePow2BitShift);
|
||||||
int targetItemIndex = checked((int)(index & list._blockSizeMinus1));
|
int targetItemIndex = (int)(index & list._blockSizeMinus1);
|
||||||
|
|
||||||
int lastTakenBlockIndex = list.LastBlockWithData;
|
int lastTakenBlockIndex = list.LastBlockWithData;
|
||||||
while (sourceBlockIndex < lastTakenBlockIndex || (sourceBlockIndex == lastTakenBlockIndex && (sourceItemIndex < nextItemIndex || sourceBlockIndex != list._nextItemBlockIndex)))
|
while (sourceBlockIndex < lastTakenBlockIndex || (sourceBlockIndex == lastTakenBlockIndex && (sourceItemIndex < nextItemIndex || sourceBlockIndex != list._nextItemBlockIndex)))
|
||||||
@@ -980,9 +980,9 @@ namespace Recyclable.Collections
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public int IndexOf(T item) => _longCount == 0
|
public int IndexOf(T item) => _longCount == 0
|
||||||
? ItemNotFoundIndex
|
? ItemNotFoundIndex
|
||||||
//// Optimization for tiny collections to avoid any vars etc.
|
// Optimization for tiny collections to avoid any vars etc.
|
||||||
: _longCount <= _blockSize
|
: _longCount <= _blockSize
|
||||||
? Array.IndexOf(_memoryBlocks[0], item, 0, checked((int)_longCount))
|
? Array.IndexOf(_memoryBlocks[0], item, 0, (int)_longCount)
|
||||||
: checked((int)DoIndexOfParallel(item));
|
: checked((int)DoIndexOfParallel(item));
|
||||||
|
|
||||||
public void Insert(int index, T item) => throw new NotSupportedException();
|
public void Insert(int index, T item) => throw new NotSupportedException();
|
||||||
|
|||||||
Reference in new issue
Block a user