Initial RecyclableList.AddRange performance improvements. Before cleanup.
This commit is contained in:
1 parent
66a713016f
commit
93d4ddd9cb
1 file changed
+20
-7
@@ -264,21 +264,34 @@ namespace Recyclable.Collections
|
|||||||
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public void AddRange(IList<T> items)
|
public void AddRange(IList<T> items)
|
||||||
{
|
{
|
||||||
if (items.Count == 0)
|
// & WAS SLOWER
|
||||||
{
|
// if (items.Count == 0)
|
||||||
return;
|
// {
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
|
|
||||||
var sourceItemsCount = items.Count;
|
// & WAS SLOWER
|
||||||
var targetCapacity = _count + sourceItemsCount;
|
// 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)
|
if (_capacity < targetCapacity)
|
||||||
{
|
{
|
||||||
|
// & WAS SLOWER
|
||||||
|
// _ = RecyclableListHelpers<T>.EnsureCapacity(this, _count + items.Count);
|
||||||
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
_ = RecyclableListHelpers<T>.EnsureCapacity(this, targetCapacity);
|
||||||
|
// & WAS SLOWER
|
||||||
|
// _ = RecyclableListHelpers<T>.EnsureCapacity(this, _count + sourceItemsCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
items.CopyTo(_memoryBlock, _count);
|
items.CopyTo(_memoryBlock, _count);
|
||||||
|
// & WAS SLOWER
|
||||||
|
// _count += items.Count;
|
||||||
_count = targetCapacity;
|
_count = targetCapacity;
|
||||||
|
|
||||||
_version++;
|
_version++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user