RecyclableList.DoIndexOf multiplication changed to bit shifting for better performance.
This commit is contained in:
1 parent
80756aff44
commit
d6b351b1eb
1 file changed
+2
-2
@@ -209,7 +209,7 @@ namespace Recyclable.Collections
|
||||
itemIndex = Array.IndexOf(memoryBlocksSpan[blockIndex], item, 0, blockSize);
|
||||
if (itemIndex >= 0)
|
||||
{
|
||||
return itemIndex + (blockIndex * blockSize);
|
||||
return itemIndex + (blockIndex << (31 - BitOperations.LeadingZeroCount((uint)blockSize)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace Recyclable.Collections
|
||||
return ItemNotFoundIndex;
|
||||
}
|
||||
|
||||
return itemIndex >= 0 ? itemIndex + (lastBlockIndex * blockSize) : ItemNotFoundIndex;
|
||||
return itemIndex >= 0 ? itemIndex + (lastBlockIndex << (31 - BitOperations.LeadingZeroCount((uint)blockSize))) : ItemNotFoundIndex;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
|
||||
Reference in new issue
Block a user