From e53d6a134c6de1229bef6142c5703e03cfb3df6b Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 16 Jul 2023 12:11:38 +0200 Subject: [PATCH] RecyclableList.Insert performance improvement. Local variable removed. --- Recyclable.Collections/RecyclableList.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 3139163..a2c8827 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -293,7 +293,6 @@ namespace Recyclable.Collections int blockIndex, sourceBlockSize = items.BlockSize, - // TODO: Convert to bit-shift lastBlockIndex = (int)(sourceItemsCount >> items._blockSizePow2BitShift) - 1; for (blockIndex = 0; blockIndex <= lastBlockIndex; blockIndex++) @@ -381,10 +380,9 @@ namespace Recyclable.Collections public void Insert(int index, T item) { int oldCount = _count; - int requestedCapacity = oldCount + 1; - if (_capacity < requestedCapacity) + if (_capacity < oldCount + 1) { - _capacity = RecyclableListHelpers.ResizeAndCopy(this, checked((int)BitOperations.RoundUpToPowerOf2((uint)requestedCapacity))); + _capacity = RecyclableListHelpers.ResizeAndCopy(this, checked((int)BitOperations.RoundUpToPowerOf2((uint)oldCount + 1))); } if (oldCount > 0)