|
@@ -3,7 +3,7 @@ using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
namespace Lua.Internal;
|
|
namespace Lua.Internal;
|
|
|
|
|
|
|
|
-internal ref struct PooledList<T>
|
|
|
|
|
|
|
+internal struct PooledList<T> :IDisposable
|
|
|
{
|
|
{
|
|
|
T[]? buffer;
|
|
T[]? buffer;
|
|
|
int tail;
|
|
int tail;
|
|
@@ -15,6 +15,7 @@ internal ref struct PooledList<T>
|
|
|
|
|
|
|
|
public bool IsDisposed => tail == -1;
|
|
public bool IsDisposed => tail == -1;
|
|
|
public int Count => tail;
|
|
public int Count => tail;
|
|
|
|
|
+ public int Length => tail;
|
|
|
|
|
|
|
|
public void Add(in T item)
|
|
public void Add(in T item)
|
|
|
{
|
|
{
|
|
@@ -61,6 +62,24 @@ internal ref struct PooledList<T>
|
|
|
items.CopyTo(buffer.AsSpan()[tail..]);
|
|
items.CopyTo(buffer.AsSpan()[tail..]);
|
|
|
tail += items.Length;
|
|
tail += items.Length;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public void PopUntil(int count)
|
|
|
|
|
+ {
|
|
|
|
|
+ ThrowIfDisposed();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > tail) throw new ArgumentOutOfRangeException(nameof(count));
|
|
|
|
|
+
|
|
|
|
|
+ tail = count;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void Pop(int count)
|
|
|
|
|
+ {
|
|
|
|
|
+ ThrowIfDisposed();
|
|
|
|
|
+
|
|
|
|
|
+ if (count > tail) throw new ArgumentOutOfRangeException(nameof(count));
|
|
|
|
|
+
|
|
|
|
|
+ tail -= count;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public void Clear()
|
|
public void Clear()
|
|
|
{
|
|
{
|