From abbd568c6b19b3db3765220d90c409c5168d07e0 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Tue, 11 Apr 2023 20:24:26 +0200 Subject: [PATCH] RecyclableList.LastTakenBlockIndex renamed to LastBlockWithData. Tiny cleanup. --- .../RecyclableCollectionsBenchmarks.RecyclableList.cs | 8 ++++---- Recyclable.Collections/RecyclableList.cs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs index 801fad9..71c4242 100644 --- a/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs +++ b/Recyclable.Collections.Benchmarks/RecyclableCollectionsBenchmarks.RecyclableList.cs @@ -110,7 +110,7 @@ namespace Recyclable.Collections.Benchmarks int blockSize = data.BlockSize; int nextItemBlockIndex = data.NextItemBlockIndex; - var memoryBlocks = new Span(data.MemoryBlocks, 0, data.LastTakenBlockIndex + 1); + var memoryBlocks = new Span(data.MemoryBlocks, 0, data.LastBlockWithData + 1); for (var blockIndex = 0; blockIndex < nextItemBlockIndex; blockIndex++) { var memoryBlock = new Span(memoryBlocks[blockIndex], 0, blockSize); @@ -120,7 +120,7 @@ namespace Recyclable.Collections.Benchmarks } } - if (nextItemBlockIndex == data.LastTakenBlockIndex) + if (nextItemBlockIndex == data.LastBlockWithData) { var memoryBlock = new Span(memoryBlocks[nextItemBlockIndex], 0, data.NextItemIndex); @@ -149,7 +149,7 @@ namespace Recyclable.Collections.Benchmarks } } - if (nextItemBlockIndex == data.LastTakenBlockIndex) + if (nextItemBlockIndex == data.LastBlockWithData) { var memoryBlock = memoryBlocks[nextItemBlockIndex]; blockSize = data.NextItemIndex; @@ -203,7 +203,7 @@ namespace Recyclable.Collections.Benchmarks } } - if (nextItemBlockIndex == data.LastTakenBlockIndex) + if (nextItemBlockIndex == data.LastBlockWithData) { memoryBlock = memoryBlocks[nextItemBlockIndex]; blockSize = data.NextItemIndex; diff --git a/Recyclable.Collections/RecyclableList.cs b/Recyclable.Collections/RecyclableList.cs index 20723c2..092f2e3 100644 --- a/Recyclable.Collections/RecyclableList.cs +++ b/Recyclable.Collections/RecyclableList.cs @@ -34,7 +34,7 @@ namespace Recyclable.Collections public int Count => checked((int)_longCount); public bool IsReadOnly { get; } - public int LastTakenBlockIndex => _nextItemBlockIndex - (_nextItemIndex > 0 ? 0 : 1); + public int LastBlockWithData => _nextItemBlockIndex - (_nextItemIndex > 0 ? 0 : 1); protected long _longCount; @@ -61,7 +61,7 @@ namespace Recyclable.Collections int targetBlockIndex = checked((int)(index >> list._blockSizePow2Shift)); int targetItemIndex = checked((int)(index & (blockSize - 1))); - int lastTakenBlockIndex = list.LastTakenBlockIndex; + int lastTakenBlockIndex = list.LastBlockWithData; while (sourceBlockIndex < lastTakenBlockIndex || (sourceBlockIndex == lastTakenBlockIndex && (sourceItemIndex < nextItemIndex || sourceBlockIndex != list._nextItemBlockIndex))) { int toCopy = sourceBlockIndex < lastTakenBlockIndex || nextItemIndex == 0 @@ -334,7 +334,7 @@ namespace Recyclable.Collections : requestedCapacity; int blockSize = list._blockSize; - newCapacity = RecyclableList.Resize(list, blockSize, list._blockSizePow2Shift, newCapacity); + newCapacity = Resize(list, blockSize, list._blockSizePow2Shift, newCapacity); if (newCapacity > 0 && blockSize != list._memoryBlocks[0].Length) { blockSize = list._memoryBlocks[0].Length; @@ -814,7 +814,7 @@ namespace Recyclable.Collections ? ItemNotFoundIndex : _nextItemBlockIndex == 0 || (_nextItemBlockIndex == 1 && _nextItemIndex == 0) ? Array.IndexOf(_memoryBlocks[0], item, 0, checked((int)_longCount)) - : checked((int)DoIndexOf(item, _memoryBlocks, LastTakenBlockIndex, _blockSize, _nextItemIndex)); + : checked((int)DoIndexOf(item, _memoryBlocks, LastBlockWithData, _blockSize, _nextItemIndex)); public void Insert(int index, T item) => throw new NotSupportedException(); @@ -823,7 +823,7 @@ namespace Recyclable.Collections ? ItemNotFoundIndex : _nextItemBlockIndex == 0 || (_nextItemBlockIndex == 1 && _nextItemIndex == 0) ? Array.IndexOf(_memoryBlocks[0], item, 0, checked((int)_longCount)) - : DoIndexOf(item, _memoryBlocks, LastTakenBlockIndex, _blockSize, _nextItemIndex); + : DoIndexOf(item, _memoryBlocks, LastBlockWithData, _blockSize, _nextItemIndex); [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public bool Remove(T item)