Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Commit

Permalink
Updated removedItems to use an array instead of a List<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Hoefling committed Mar 11, 2019
1 parent 91eb11d commit 91cf013
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,17 @@ protected override void RemoveItemsRange(int index, int count)
length = index + count;
}

List<T> removedItems = new List<T>();
for (int i = index; i < length; i++)
T[] oldItems = new T[Items.Count];
if (Items is List<T> list)
{
removedItems.Add(this[i]);
list.CopyTo(oldItems);
}
else
{
for (int i = 0; i < oldItems.Length; i++)
{
oldItems[i] = this[i];
}
}

bool ignore = _skipRaisingEvents;
Expand All @@ -172,6 +179,12 @@ protected override void RemoveItemsRange(int index, int count)

if (count > 0 && !_skipRaisingEvents)
{
T[] removedItems = new T[count];
for (int i = 0; i < count; i++)
{
removedItems[i] = oldItems[index + i];
}

OnCountPropertyChanged();
OnIndexerPropertyChanged();
OnCollectionChanged(NotifyCollectionChangedAction.Remove, removedItems, index);
Expand Down

0 comments on commit 91cf013

Please sign in to comment.