RecyclableList.DoIndexOf multiplication changed to bit shifting for better performance.

This commit is contained in:
mlemanczyk committed 2023-04-01 20:01:34 +02:00
1 parent 80756aff44
commit d6b351b1eb
1 file changed
+2 -2
+2 -2
View File
@@ -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)]