RecyclableList.Clear functionality copied to .Dispose for better performance.
This commit is contained in:
1 parent
5fea2b44e4
commit
76dd62a5e2
1 file changed
+12
-4
@@ -534,15 +534,23 @@ namespace Recyclable.Collections
|
|||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (_capacity > 0)
|
_version++;
|
||||||
|
if (_count != 0)
|
||||||
{
|
{
|
||||||
Clear();
|
if (NeedsClearing)
|
||||||
if (_count is >= RecyclableDefaults.MinPooledArrayLength)
|
|
||||||
{
|
{
|
||||||
|
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.
|
// If anything, it has been already cleared by .Clear(), Remove() or RemoveAt() methods, as the list was modified / disposed.
|
||||||
_arrayPool.Return(_memoryBlock, false);
|
_arrayPool.Return(_memoryBlock, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user