RecyclableLongList.Remove & .RemoveAt performance improvements.
This commit is contained in:
1 parent
66364ce4f9
commit
8714b5b977
1 file changed
+17
-29
@@ -875,19 +875,20 @@ namespace Recyclable.Collections
|
|||||||
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)]
|
||||||
public bool Remove(T item)
|
public bool Remove(T item)
|
||||||
{
|
{
|
||||||
var index = LongIndexOf(item);
|
long index;
|
||||||
if (index >= 0)
|
if ((index = LongIndexOf(item)) >= 0)
|
||||||
{
|
{
|
||||||
_longCount--;
|
if (index < --_longCount)
|
||||||
|
|
||||||
if (index < _longCount)
|
|
||||||
{
|
{
|
||||||
Helpers.CopyFollowingItems(this, index);
|
Helpers.CopyFollowingItems(this, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex > 0)
|
if (_nextItemIndex > 0)
|
||||||
{
|
{
|
||||||
_nextItemIndex--;
|
if (--_nextItemIndex == 0)
|
||||||
|
{
|
||||||
|
_lastBlockWithData--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -895,11 +896,6 @@ namespace Recyclable.Collections
|
|||||||
_nextItemBlockIndex--;
|
_nextItemBlockIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex == 0)
|
|
||||||
{
|
|
||||||
_lastBlockWithData--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NeedsClearing)
|
if (NeedsClearing)
|
||||||
{
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
@@ -948,16 +944,17 @@ namespace Recyclable.Collections
|
|||||||
Helpers.ThrowIndexOutOfRangeException($"Argument \"{nameof(index)}\" = {index} is out of range. Expected value between 0 and {_longCount - 1}");
|
Helpers.ThrowIndexOutOfRangeException($"Argument \"{nameof(index)}\" = {index} is out of range. Expected value between 0 and {_longCount - 1}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount--;
|
if (index < --_longCount)
|
||||||
|
|
||||||
if (index < _longCount)
|
|
||||||
{
|
{
|
||||||
Helpers.CopyFollowingItems(this, index);
|
Helpers.CopyFollowingItems(this, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex > 0)
|
if (_nextItemIndex > 0)
|
||||||
{
|
{
|
||||||
_nextItemIndex--;
|
if (--_nextItemIndex == 0)
|
||||||
|
{
|
||||||
|
_lastBlockWithData--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -965,11 +962,6 @@ namespace Recyclable.Collections
|
|||||||
_nextItemBlockIndex--;
|
_nextItemBlockIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex == 0)
|
|
||||||
{
|
|
||||||
_lastBlockWithData--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NeedsClearing)
|
if (NeedsClearing)
|
||||||
{
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
@@ -988,16 +980,17 @@ namespace Recyclable.Collections
|
|||||||
Helpers.ThrowIndexOutOfRangeException($"Argument \"{nameof(index)}\" = {index} is out of range. Expected value between 0 and {_longCount - 1}");
|
Helpers.ThrowIndexOutOfRangeException($"Argument \"{nameof(index)}\" = {index} is out of range. Expected value between 0 and {_longCount - 1}");
|
||||||
}
|
}
|
||||||
|
|
||||||
_longCount--;
|
if (index < --_longCount)
|
||||||
|
|
||||||
if (index < _longCount)
|
|
||||||
{
|
{
|
||||||
Helpers.CopyFollowingItems(this, index);
|
Helpers.CopyFollowingItems(this, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex > 0)
|
if (_nextItemIndex > 0)
|
||||||
{
|
{
|
||||||
_nextItemIndex--;
|
if (--_nextItemIndex == 0)
|
||||||
|
{
|
||||||
|
_lastBlockWithData--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1005,11 +998,6 @@ namespace Recyclable.Collections
|
|||||||
_nextItemBlockIndex--;
|
_nextItemBlockIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_nextItemIndex == 0)
|
|
||||||
{
|
|
||||||
_lastBlockWithData--;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NeedsClearing)
|
if (NeedsClearing)
|
||||||
{
|
{
|
||||||
#nullable disable
|
#nullable disable
|
||||||
|
|||||||
Reference in new issue
Block a user