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)]
|
||||
public bool Remove(T item)
|
||||
{
|
||||
var index = LongIndexOf(item);
|
||||
if (index >= 0)
|
||||
long index;
|
||||
if ((index = LongIndexOf(item)) >= 0)
|
||||
{
|
||||
_longCount--;
|
||||
|
||||
if (index < _longCount)
|
||||
if (index < --_longCount)
|
||||
{
|
||||
Helpers.CopyFollowingItems(this, index);
|
||||
}
|
||||
|
||||
if (_nextItemIndex > 0)
|
||||
{
|
||||
_nextItemIndex--;
|
||||
if (--_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -895,11 +896,6 @@ namespace Recyclable.Collections
|
||||
_nextItemBlockIndex--;
|
||||
}
|
||||
|
||||
if (_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
|
||||
if (NeedsClearing)
|
||||
{
|
||||
#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}");
|
||||
}
|
||||
|
||||
_longCount--;
|
||||
|
||||
if (index < _longCount)
|
||||
if (index < --_longCount)
|
||||
{
|
||||
Helpers.CopyFollowingItems(this, index);
|
||||
}
|
||||
|
||||
if (_nextItemIndex > 0)
|
||||
{
|
||||
_nextItemIndex--;
|
||||
if (--_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -965,11 +962,6 @@ namespace Recyclable.Collections
|
||||
_nextItemBlockIndex--;
|
||||
}
|
||||
|
||||
if (_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
|
||||
if (NeedsClearing)
|
||||
{
|
||||
#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}");
|
||||
}
|
||||
|
||||
_longCount--;
|
||||
|
||||
if (index < _longCount)
|
||||
if (index < --_longCount)
|
||||
{
|
||||
Helpers.CopyFollowingItems(this, index);
|
||||
}
|
||||
|
||||
if (_nextItemIndex > 0)
|
||||
{
|
||||
_nextItemIndex--;
|
||||
if (--_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1005,11 +998,6 @@ namespace Recyclable.Collections
|
||||
_nextItemBlockIndex--;
|
||||
}
|
||||
|
||||
if (_nextItemIndex == 0)
|
||||
{
|
||||
_lastBlockWithData--;
|
||||
}
|
||||
|
||||
if (NeedsClearing)
|
||||
{
|
||||
#nullable disable
|
||||
|
||||
Reference in new issue
Block a user