Rename queue chunk to BiDirectional prefix

This commit is contained in:
Marek Lemańczyk committed 2025-07-14 00:28:03 +02:00
1 parent 3a712dbe57
commit 713a8ffdba
3 files changed
+21 -21

No files matched your search

@@ -1,6 +1,6 @@
namespace Recyclable.Collections.Pools namespace Recyclable.Collections.Pools
{ {
public sealed class RecyclableArrayPoolQueueChunk<T> public sealed class BiDirectionalRecyclableArrayPoolChunk<T>
{ {
private static readonly T[] _empty = Array.Empty<T>(); private static readonly T[] _empty = Array.Empty<T>();
@@ -9,10 +9,10 @@ namespace Recyclable.Collections.Pools
internal T[] Buffer; internal T[] Buffer;
internal int Top; internal int Top;
internal int Bottom; internal int Bottom;
internal RecyclableArrayPoolQueueChunk<T>? Previous; internal BiDirectionalRecyclableArrayPoolChunk<T>? Previous;
internal RecyclableArrayPoolQueueChunk<T>? Next; internal BiDirectionalRecyclableArrayPoolChunk<T>? Next;
public RecyclableArrayPoolQueueChunk() public BiDirectionalRecyclableArrayPoolChunk()
{ {
Buffer = _empty; Buffer = _empty;
} }
@@ -2,14 +2,14 @@ using Microsoft.Extensions.ObjectPool;
namespace Recyclable.Collections.Pools namespace Recyclable.Collections.Pools
{ {
public static class RecyclableArrayPoolQueueChunkPool<T> public static class BiDirectionalRecyclableArrayPoolChunkPool<T>
{ {
private static readonly ObjectPool<RecyclableArrayPoolQueueChunk<T>> _pool = private static readonly ObjectPool<BiDirectionalRecyclableArrayPoolChunk<T>> _pool =
new DefaultObjectPool<RecyclableArrayPoolQueueChunk<T>>(new DefaultPooledObjectPolicy<RecyclableArrayPoolQueueChunk<T>>()); new DefaultObjectPool<BiDirectionalRecyclableArrayPoolChunk<T>>(new DefaultPooledObjectPolicy<BiDirectionalRecyclableArrayPoolChunk<T>>());
public static RecyclableArrayPoolQueueChunk<T> Rent() => _pool.Get(); public static BiDirectionalRecyclableArrayPoolChunk<T> Rent() => _pool.Get();
public static void Return(RecyclableArrayPoolQueueChunk<T> chunk) public static void Return(BiDirectionalRecyclableArrayPoolChunk<T> chunk)
{ {
chunk.Top = 0; chunk.Top = 0;
chunk.Bottom = 0; chunk.Bottom = 0;
@@ -18,7 +18,7 @@ namespace Recyclable.Collections.Pools
_pool.Return(chunk); _pool.Return(chunk);
} }
public static void Dispose(RecyclableArrayPoolQueueChunk<T> chunk, bool needsClearing) public static void Dispose(BiDirectionalRecyclableArrayPoolChunk<T> chunk, bool needsClearing)
{ {
var buffer = chunk.Buffer; var buffer = chunk.Buffer;
if (buffer.Length >= RecyclableDefaults.MinPooledArrayLength) if (buffer.Length >= RecyclableDefaults.MinPooledArrayLength)
@@ -26,7 +26,7 @@ namespace Recyclable.Collections.Pools
RecyclableArrayPool<T>.ReturnShared(buffer, needsClearing); RecyclableArrayPool<T>.ReturnShared(buffer, needsClearing);
} }
chunk.Buffer = RecyclableArrayPoolQueueChunk<T>.Empty; chunk.Buffer = BiDirectionalRecyclableArrayPoolChunk<T>.Empty;
chunk.Top = 0; chunk.Top = 0;
chunk.Bottom = 0; chunk.Bottom = 0;
chunk.Previous = null; chunk.Previous = null;
+10 -10
View File
@@ -10,9 +10,9 @@ namespace Recyclable.Collections
private static readonly bool _needsClearing = !typeof(T).IsValueType; private static readonly bool _needsClearing = !typeof(T).IsValueType;
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static RecyclableArrayPoolQueueChunk<T> RentChunk(int size, RecyclableArrayPoolQueueChunk<T>? previous) private static BiDirectionalRecyclableArrayPoolChunk<T> RentChunk(int size, BiDirectionalRecyclableArrayPoolChunk<T>? previous)
{ {
var chunk = RecyclableArrayPoolQueueChunkPool<T>.Rent(); var chunk = BiDirectionalRecyclableArrayPoolChunkPool<T>.Rent();
if (chunk.Buffer.Length < size) if (chunk.Buffer.Length < size)
{ {
if (chunk.Buffer.Length >= RecyclableDefaults.MinPooledArrayLength) if (chunk.Buffer.Length >= RecyclableDefaults.MinPooledArrayLength)
@@ -33,19 +33,19 @@ namespace Recyclable.Collections
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void ReturnChunk(RecyclableArrayPoolQueueChunk<T> chunk) private static void ReturnChunk(BiDirectionalRecyclableArrayPoolChunk<T> chunk)
{ {
RecyclableArrayPoolQueueChunkPool<T>.Return(chunk); BiDirectionalRecyclableArrayPoolChunkPool<T>.Return(chunk);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void DisposeChunk(RecyclableArrayPoolQueueChunk<T> chunk) private static void DisposeChunk(BiDirectionalRecyclableArrayPoolChunk<T> chunk)
{ {
RecyclableArrayPoolQueueChunkPool<T>.Dispose(chunk, _needsClearing); BiDirectionalRecyclableArrayPoolChunkPool<T>.Dispose(chunk, _needsClearing);
} }
private RecyclableArrayPoolQueueChunk<T> _head; private BiDirectionalRecyclableArrayPoolChunk<T> _head;
private RecyclableArrayPoolQueueChunk<T> _tail; private BiDirectionalRecyclableArrayPoolChunk<T> _tail;
private bool _disposed; private bool _disposed;
private long _capacity; private long _capacity;
private long _count; private long _count;
@@ -204,8 +204,8 @@ namespace Recyclable.Collections
public struct Enumerator : IEnumerator<T> public struct Enumerator : IEnumerator<T>
{ {
private readonly RecyclableArrayPoolQueueChunk<T>? _start; private readonly BiDirectionalRecyclableArrayPoolChunk<T>? _start;
private RecyclableArrayPoolQueueChunk<T>? _chunk; private BiDirectionalRecyclableArrayPoolChunk<T>? _chunk;
private int _index; private int _index;
private T? _current; private T? _current;