Refactor collections to use 'scoped in T' parameters
Updated Add/Remove/Enqueue/Push/etc. methods in core unsafe collections to accept parameters as 'scoped in T' for improved performance and safety. Bumped assembly versions in both csproj files.
This commit is contained in:
@@ -74,7 +74,7 @@ public unsafe struct UnsafeHashSet<T> : IUnsafeHashCollection<T>
|
||||
/// <param name="item">The value to add.</param>
|
||||
/// <returns>True if the value was not already present.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Add(T item)
|
||||
public bool Add(scoped in T item)
|
||||
{
|
||||
return -1 != _helper.TryAdd(item);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public unsafe struct UnsafeHashSet<T> : IUnsafeHashCollection<T>
|
||||
/// <param name="item">The value to remove.</param>
|
||||
/// <returns>True if the value was present.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Remove(T item)
|
||||
public bool Remove(scoped in T item)
|
||||
{
|
||||
return -1 != _helper.TryRemove(item);
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public unsafe struct UnsafeHashSet<T> : IUnsafeHashCollection<T>
|
||||
/// <param name="item">The value to check for.</param>
|
||||
/// <returns>True if the value was present.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool Contains(T item)
|
||||
public bool Contains(scoped in T item)
|
||||
{
|
||||
return -1 != _helper.Find(item);
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ public unsafe struct UnsafeList<T> : IUnsafeCollection<T>
|
||||
/// Adds a value to a collection without resizing it, ensuring capacity is checked before insertion.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to be added to the collection.</param>
|
||||
public void AddNoResize(T value)
|
||||
public void AddNoResize(scoped in T value)
|
||||
{
|
||||
var idx = Interlocked.Increment(ref listData->_count) - 1;
|
||||
listData->CheckNoResizeCapacity(idx, 1);
|
||||
@@ -305,7 +305,7 @@ public unsafe struct UnsafeList<T> : IUnsafeCollection<T>
|
||||
/// Adds a new element to the end of the list, resizing the internal array if necessary.
|
||||
/// </summary>
|
||||
/// <param name="value">The element to be added to the list.</param>
|
||||
public void Add(T value)
|
||||
public void Add(scoped in T value)
|
||||
{
|
||||
if (_count >= Capacity)
|
||||
{
|
||||
@@ -320,7 +320,7 @@ public unsafe struct UnsafeList<T> : IUnsafeCollection<T>
|
||||
/// Adds the specified value to the collection without resizing the underlying storage.
|
||||
/// </summary>
|
||||
/// <param name="value">The value to add to the collection.</param>
|
||||
public void AddNoResize(T value)
|
||||
public void AddNoResize(scoped in T value)
|
||||
{
|
||||
CheckNoResizeCapacity(1);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public unsafe struct UnsafeParallelQueue<T> : IDisposable
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void Enqueue(T item)
|
||||
public void Enqueue(scoped in T item)
|
||||
{
|
||||
_queue->Enqueue(item);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public unsafe struct UnsafeParallelQueue<T> : IDisposable
|
||||
/// <summary>
|
||||
/// Try to enqueue an item. Expands automatically if the current chunk is full.
|
||||
/// </summary>
|
||||
public void Enqueue(T item)
|
||||
public void Enqueue(scoped in T item)
|
||||
{
|
||||
SpinWait spin = new SpinWait();
|
||||
|
||||
|
||||
@@ -122,7 +122,7 @@ public unsafe struct UnsafeQueue<T> : IUnsafeCollection<T>
|
||||
/// stored in a circular buffer.
|
||||
/// </summary>
|
||||
/// <param name="value">The item to be added to the collection.</param>
|
||||
public void Enqueue(T value)
|
||||
public void Enqueue(scoped in T value)
|
||||
{
|
||||
if (_count >= Capacity)
|
||||
{
|
||||
|
||||
@@ -206,7 +206,7 @@ public unsafe struct UnsafeSlotMap<T> : IUnsafeCollection<T>
|
||||
/// <param name="item">The item to add to the collection.</param>
|
||||
/// <param name="generation">When this method returns, contains the Generation number associated with the slot where the item was stored.</param>
|
||||
/// <returns>The index of the slot in which the item was stored.</returns>
|
||||
public int Add(T item, out int generation)
|
||||
public int Add(scoped in T item, out int generation)
|
||||
{
|
||||
if (_freeSlots.Count > 0)
|
||||
{
|
||||
|
||||
@@ -158,7 +158,7 @@ public unsafe struct UnsafeSparseSet<T> : IUnsafeCollection<T>
|
||||
/// <param name="value">The value to add to the sparse set.</param>
|
||||
/// <param name="generation">Outputs the Generation number associated with the added value.</param>
|
||||
/// <returns>A unique sparse index that can be used to reference this value.</returns>
|
||||
public int Add(T value, out int generation)
|
||||
public int Add(scoped in T value, out int generation)
|
||||
{
|
||||
if (!_freeSparse.TryPop(out var sparseIndex))
|
||||
{
|
||||
|
||||
@@ -119,7 +119,7 @@ public unsafe struct UnsafeStack<T> : IUnsafeCollection<T>
|
||||
/// Adds an element to the top of the stack.
|
||||
/// </summary>
|
||||
/// <param name="value">The element to add to the stack.</param>
|
||||
public void Push(T value)
|
||||
public void Push(scoped in T value)
|
||||
{
|
||||
if (_count >= Capacity)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user