mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 19:10:32 +00:00
fix(Pool): Return now checks for null entries to avoid nulls creeping into the pool
This commit is contained in:
parent
5f0c2467fb
commit
e01b618dcb
@ -32,7 +32,15 @@ public Pool(Func<T> objectGenerator, int initialCapacity)
|
|||||||
|
|
||||||
// return an element to the pool
|
// return an element to the pool
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
public void Return(T item) => objects.Push(item);
|
public void Return(T item)
|
||||||
|
{
|
||||||
|
// make sure we can't accidentally insert null values into the pool.
|
||||||
|
// debugging this would be hard since it would only show on get().
|
||||||
|
if (item == null)
|
||||||
|
throw new ArgumentNullException(nameof(item));
|
||||||
|
|
||||||
|
objects.Push(item);
|
||||||
|
}
|
||||||
|
|
||||||
// count to see how many objects are in the pool. useful for tests.
|
// count to see how many objects are in the pool. useful for tests.
|
||||||
public int Count => objects.Count;
|
public int Count => objects.Count;
|
||||||
|
@ -34,6 +34,15 @@ public void ReturnAndTake()
|
|||||||
Assert.That(pool.Get(), Is.EqualTo("returned"));
|
Assert.That(pool.Get(), Is.EqualTo("returned"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReturnNull()
|
||||||
|
{
|
||||||
|
// make sure we can't accidentally insert null values into the pool.
|
||||||
|
// debugging this would be hard since it would only show on get().
|
||||||
|
Assert.That(() => pool.Return(null), Throws.ArgumentNullException);
|
||||||
|
Assert.That(pool.Count, Is.EqualTo(0));
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void Count()
|
public void Count()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user