RecyclableList.Clear functionality copied to .Dispose for better performance.

This commit is contained in:
mlemanczyk committed 2023-06-28 23:15:53 +02:00
1 parent 5fea2b44e4
commit 76dd62a5e2
1 file changed
+12 -4
+12 -4
View File
@@ -534,15 +534,23 @@ namespace Recyclable.Collections
public void Dispose()
{
if (_capacity > 0)
_version++;
if (_count != 0)
{
Clear();
if (_count is >= RecyclableDefaults.MinPooledArrayLength)
if (NeedsClearing)
{
Array.Clear(_memoryBlock, 0, _count);
}
_count = 0;
}
if (_capacity >= RecyclableDefaults.MinPooledArrayLength)
{
_capacity = 0;
// If anything, it has been already cleared by .Clear(), Remove() or RemoveAt() methods, as the list was modified / disposed.
_arrayPool.Return(_memoryBlock, false);
}
}
GC.SuppressFinalize(this);
}