From 1296f002a38d97829294432da81767551537a847 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Sat, 20 Mar 2021 07:48:10 +0100 Subject: [PATCH] list remove range fix, remove range fast --- BeefLibs/corlib/src/Collections/List.bf | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/BeefLibs/corlib/src/Collections/List.bf b/BeefLibs/corlib/src/Collections/List.bf index dd376115..605cb723 100644 --- a/BeefLibs/corlib/src/Collections/List.bf +++ b/BeefLibs/corlib/src/Collections/List.bf @@ -578,7 +578,7 @@ namespace System.Collections public void RemoveRange(int index, int count) { Debug.Assert((uint)index + (uint)count <= (uint)mSize); - if (index + count < mSize - 1) + if (index + count <= mSize - 1) { for (int i = index; i < mSize - count; i++) mItems[i] = mItems[i + count]; @@ -589,12 +589,29 @@ namespace System.Collections #endif } + /// Will change the order of items in the list public void RemoveAtFast(int index) { Debug.Assert((uint32)index < (uint32)mSize); mSize--; if (mSize > 0) - mItems[index] = mItems[mSize]; + mItems[index] = mItems[mSize]; +#if VERSION_LIST + mVersion++; +#endif + } + + /// Will change the order of items in the list + public void RemoveRangeFast(int index, int count) + { + Debug.Assert((uint)index + (uint)count <= (uint)mSize); + if (index + count <= mSize - 1) + { + int moveCount = Math.Min(count, mSize - (index + count)); + for (int i < moveCount) + mItems[index + i] = mItems[mSize - moveCount + i]; + } + mSize -= (.)count; #if VERSION_LIST mVersion++; #endif