diff --git a/Recyclable.Collections.Benchmarks/POC/RecyclableLongListHelpers.CopyFollowingItems.Benchmarks.cs b/Recyclable.Collections.Benchmarks/POC/RecyclableLongListHelpers.CopyFollowingItems.Benchmarks.cs deleted file mode 100644 index 267749f..0000000 --- a/Recyclable.Collections.Benchmarks/POC/RecyclableLongListHelpers.CopyFollowingItems.Benchmarks.cs +++ /dev/null @@ -1,36 +0,0 @@ -using BenchmarkDotNet.Attributes; - -namespace Recyclable.Collections.Benchmarks.POC -{ - public enum RecyclableLongListHelpersCopyFollowingItemsBenchmarkType - { - Undefined, - Old, - New, - } - - public class RecyclableLongListHelpersCopyFollowingItemsBenchmarks : RecyclableBenchmarkBase - { - [Params(RecyclableLongListHelpersCopyFollowingItemsBenchmarkType.Old)] - public override RecyclableLongListHelpersCopyFollowingItemsBenchmarkType BaseDataType { get => base.BaseDataType; set => base.BaseDataType = value; } - - [Params(RecyclableLongListHelpersCopyFollowingItemsBenchmarkType.New)] - public override RecyclableLongListHelpersCopyFollowingItemsBenchmarkType DataType { get => base.DataType; set => base.DataType = value; } - - protected override Action GetTestMethod(RecyclableLongListHelpersCopyFollowingItemsBenchmarkType benchmarkType) => benchmarkType switch - { - RecyclableLongListHelpersCopyFollowingItemsBenchmarkType.Old => CopyFollowingItemsOld, - RecyclableLongListHelpersCopyFollowingItemsBenchmarkType.New => CopyFollowingItemsNew, - _ => throw CreateUnknownBenchmarkTypeException(benchmarkType), - }; - - protected override void PrepareData(RecyclableLongListHelpersCopyFollowingItemsBenchmarkType benchmarkType) - { - base.PrepareData(RecyclableCollectionsBenchmarkSource.Array); - base.PrepareData(RecyclableCollectionsBenchmarkSource.RecyclableLongList); - } - - public void CopyFollowingItemsOld() => RecyclableLongList.Helpers.CopyFollowingItemsOld(TestObjectsAsRecyclableLongList, 0); - public void CopyFollowingItemsNew() => RecyclableLongList.Helpers.CopyFollowingItems(TestObjectsAsRecyclableLongList, 0); - } -} diff --git a/Recyclable.Collections/RecyclableLongList.Helpers.cs b/Recyclable.Collections/RecyclableLongList.Helpers.cs index ecd5f25..a6d327f 100644 --- a/Recyclable.Collections/RecyclableLongList.Helpers.cs +++ b/Recyclable.Collections/RecyclableLongList.Helpers.cs @@ -8,52 +8,6 @@ namespace Recyclable.Collections { internal static class Helpers { - [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] - public static void CopyFollowingItemsOld(RecyclableLongList list, long destinationItemIndex) - { - T[][] memoryBlocks = list._memoryBlocks; - int nextItemIndex = list._nextItemIndex; - int blockSize = list._blockSize; - int sourceBlockIndex = (int)((destinationItemIndex + 1) >> list._blockSizePow2BitShift); - int sourceItemIndex = (int)((destinationItemIndex + 1) & list._blockSizeMinus1); - - int targetBlockIndex = (int)(destinationItemIndex >> list._blockSizePow2BitShift); - int targetItemIndex = (int)(destinationItemIndex & list._blockSizeMinus1); - - int lastTakenBlockIndex = list._lastBlockWithData; - while (sourceBlockIndex < lastTakenBlockIndex || (sourceBlockIndex == lastTakenBlockIndex && (sourceItemIndex < nextItemIndex || sourceBlockIndex != list._nextItemBlockIndex))) - { - int toCopy = sourceBlockIndex < lastTakenBlockIndex || nextItemIndex == 0 - ? blockSize - (sourceItemIndex >= targetItemIndex ? sourceItemIndex : targetItemIndex) - : Math.Min(nextItemIndex, blockSize - targetItemIndex); - - Array.Copy(memoryBlocks[sourceBlockIndex], sourceItemIndex, memoryBlocks[targetBlockIndex], targetItemIndex, toCopy); - - // We didn't have enough room in the target array block. There are still items in the source array block to copy. - if (sourceItemIndex + toCopy < blockSize) - { - sourceItemIndex += toCopy; - targetBlockIndex++; - targetItemIndex = 0; - } - // We copied all the source items in the current array block. But have we filled the target? - else - { - sourceItemIndex = 0; - sourceBlockIndex++; - if (targetItemIndex + toCopy < blockSize) - { - targetItemIndex += toCopy; - } - else - { - targetBlockIndex++; - targetItemIndex = 0; - } - } - } - } - [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] public static void CopyFollowingItems(RecyclableLongList list, long destinationItemIndex) {