From 13fa23ac13b491e87eda82b6a02e4b19a0b68c61 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sun, 30 Apr 2023 22:21:58 +0200 Subject: [PATCH] RecyclableArrayList.AsArray() method converted to property for better performance. --- .../POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs | 4 ++-- Recyclable.Collections/RecyclableArrayList.cs | 2 +- Recyclable.Collections/RecyclableList.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs index 5f4ebe2..da5f07c 100644 --- a/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs +++ b/Recyclable.Collections.Benchmarks/POC/RecyclableListPoc.Benchmarks.EnsureCapacity.cs @@ -498,7 +498,7 @@ namespace Recyclable.Collections.Benchmarks.POC targetBlockIndex = _nextItemBlockIndex, memoryBlockCount = _memoryBlocks.Length; - Span itemsSpan = new(items.AsArray(), 0, items.Count); + Span itemsSpan = new(items.AsArray, 0, items.Count); Span memoryBlocksSpan = new(_memoryBlocks, 0, memoryBlockCount); Span targetBlockArraySpan = new(memoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex); while (targetBlockArraySpan.Length <= itemsSpan.Length) @@ -1397,7 +1397,7 @@ namespace Recyclable.Collections.Benchmarks.POC targetBlockIndex = _nextItemBlockIndex, memoryBlockCount = _memoryBlocks.Length; - Span itemsSpan = new(items.AsArray(), 0, items.Count); + Span itemsSpan = new(items.AsArray, 0, items.Count); Span memoryBlocksSpan = new(_memoryBlocks, 0, memoryBlockCount); Span targetBlockArraySpan = new(memoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex); while (targetBlockArraySpan.Length <= itemsSpan.Length) diff --git a/Recyclable.Collections/RecyclableArrayList.cs b/Recyclable.Collections/RecyclableArrayList.cs index 155e7a1..8160579 100644 --- a/Recyclable.Collections/RecyclableArrayList.cs +++ b/Recyclable.Collections/RecyclableArrayList.cs @@ -368,7 +368,7 @@ namespace Recyclable.Collections _count = targetItemIdx; } - public T[] AsArray() => _memoryBlock; + public T[] AsArray => _memoryBlock; public void Clear() { diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 9f2527d..eaa3de5 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -681,7 +681,7 @@ namespace Recyclable.Collections targetBlockIndex = _nextItemBlockIndex, memoryBlockCount = _reservedBlockCount; - Span itemsSpan = new(items.AsArray(), 0, items.Count); + Span itemsSpan = new(items.AsArray, 0, items.Count); Span memoryBlocksSpan = new(_memoryBlocks, 0, memoryBlockCount); Span targetBlockArraySpan = new(memoryBlocksSpan[targetBlockIndex], _nextItemIndex, blockSize - _nextItemIndex); while (targetBlockArraySpan.Length <= itemsSpan.Length)