From 91cf0139693372cf488eaec2c978973af885b2bb Mon Sep 17 00:00:00 2001 From: Andrew Hoefling Date: Sun, 10 Mar 2019 22:07:56 -0400 Subject: [PATCH] Updated removedItems to use an array instead of a List --- .../ObjectModel/ObservableCollection.cs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs b/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs index 032ae1a697ad..0ea90f49e780 100644 --- a/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs +++ b/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs @@ -146,10 +146,17 @@ protected override void RemoveItemsRange(int index, int count) length = index + count; } - List removedItems = new List(); - for (int i = index; i < length; i++) + T[] oldItems = new T[Items.Count]; + if (Items is List list) { - removedItems.Add(this[i]); + list.CopyTo(oldItems); + } + else + { + for (int i = 0; i < oldItems.Length; i++) + { + oldItems[i] = this[i]; + } } bool ignore = _skipRaisingEvents; @@ -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);