From 8147c4ecbf3daefeef38baa12f8b271b741cc7fc Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 8 Jan 2023 02:03:14 +0100 Subject: [PATCH] Decoded on GetItem/SetItem performance. It's more stable & faster without them. --- Recyclable.Collections/RecyclableList.cs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index e76f9d0..0d3f93b 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -47,28 +47,16 @@ namespace Recyclable.Collections public int BlockSize { get; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void SetItem(RecyclableBlockList arrays, in int blockSize, in long index, in T value) - => arrays[(int)(index / blockSize)][index % blockSize] = value; - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static T GetItem(RecyclableBlockList arrays, in int blockSize, in long index) - => arrays[(int)(index / blockSize)][index % blockSize]; - public T this[long index] { - //get => GetItem(MemoryBlocks, BlockSize, index); - //set => SetItem(MemoryBlocks, BlockSize, index, value); - get => _memoryBlocks[(int)(index / BlockSize)][index % BlockSize]; - set => _memoryBlocks[(int)(index / BlockSize)][index % BlockSize] = value; + get => _memoryBlocks[(int)(index / _blockSize)][index % _blockSize]; + set => _memoryBlocks[(int)(index / _blockSize)][index % _blockSize] = value; } public T this[int index] { - //get => GetItem(MemoryBlocks, BlockSize, index); - //set => SetItem(MemoryBlocks, BlockSize, index, value); - get => _memoryBlocks[(int)(index / BlockSize)][index % BlockSize]; - set => _memoryBlocks[(int)(index / BlockSize)][index % BlockSize] = value; + get => _memoryBlocks[index / _blockSize][index % _blockSize]; + set => _memoryBlocks[index / _blockSize][index % _blockSize] = value; } public long Capacity { get; set; } @@ -87,8 +75,7 @@ namespace Recyclable.Collections Capacity += BlockSize; } - SetItem(_memoryBlocks, BlockSize, LongCount, item); - //_arrays[_arrays.LongCount - 1][LongCount % BlockSize] = item; + memoryBlocks[oldCount / blockSize][oldCount % blockSize] = item; LongCount++; }