From 93d4ddd9cb7390c21d85e34b9314f9ede35048ae Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sat, 8 Jul 2023 14:54:24 +0200 Subject: [PATCH] Initial RecyclableList.AddRange performance improvements. Before cleanup. --- Recyclable.Collections/RecyclableList.cs | 27 ++++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 4baf582..3c63f4e 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -264,21 +264,34 @@ namespace Recyclable.Collections [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] public void AddRange(IList items) { - if (items.Count == 0) - { - return; - } + // & WAS SLOWER + // if (items.Count == 0) + // { + // return; + // } - var sourceItemsCount = items.Count; - var targetCapacity = _count + sourceItemsCount; + // & WAS SLOWER + // var sourceItemsCount = items.Count; + var targetCapacity = _count + items.Count; + // & WAS SLOWER + // var targetCapacity = _count + sourceItemsCount; + // & WAS SLOWER + // if (_capacity < _count + items.Count) + // & WAS SLOWER + // if (_capacity < _count + sourceItemsCount) if (_capacity < targetCapacity) { + // & WAS SLOWER + // _ = RecyclableListHelpers.EnsureCapacity(this, _count + items.Count); _ = RecyclableListHelpers.EnsureCapacity(this, targetCapacity); + // & WAS SLOWER + // _ = RecyclableListHelpers.EnsureCapacity(this, _count + sourceItemsCount); } items.CopyTo(_memoryBlock, _count); + // & WAS SLOWER + // _count += items.Count; _count = targetCapacity; - _version++; }