From 7e37cfc878aefdd0fd574e10bae3a14cbb2f42f8 Mon Sep 17 00:00:00 2001 From: neuecc Date: Wed, 28 Aug 2024 03:52:42 +0900 Subject: [PATCH] f --- src/ObservableCollections/ObservableList.Views.cs | 13 ++++++------- .../SynchronizedViewChangedEventArgs.cs | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ObservableCollections/ObservableList.Views.cs b/src/ObservableCollections/ObservableList.Views.cs index 4635d2d..c39a274 100644 --- a/src/ObservableCollections/ObservableList.Views.cs +++ b/src/ObservableCollections/ObservableList.Views.cs @@ -107,7 +107,7 @@ namespace ObservableCollections } } - ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Reset)); + ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Reset, true)); } } @@ -117,7 +117,7 @@ namespace ObservableCollections { this.filter = SynchronizedViewFilter.Null; this.filteredCount = list.Count; - ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Reset)); + ViewChanged?.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Reset, true)); } } @@ -208,15 +208,14 @@ namespace ObservableCollections { var i = e.NewStartingIndex; - //new CloneCollection<(T, TView)>(); using var array = new ResizableArray<(T, TView)>(e.NewItems.Length); - foreach (var item in e.NewItems) { - var v = (item, selector(item)); - list.Add(v); - this.InvokeOnAdd(ref filteredCount, ViewChanged, v, i++); + array.Add((item, selector(item))); } + + list.AddRange(array.Span); + this.InvokeOnAdd(ref filteredCount, ViewChanged, v, i++); } } // Insert diff --git a/src/ObservableCollections/SynchronizedViewChangedEventArgs.cs b/src/ObservableCollections/SynchronizedViewChangedEventArgs.cs index 31cdc1d..f5a26df 100644 --- a/src/ObservableCollections/SynchronizedViewChangedEventArgs.cs +++ b/src/ObservableCollections/SynchronizedViewChangedEventArgs.cs @@ -52,7 +52,20 @@ namespace ObservableCollections filteredCount++; if (ev != null) { - ev.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Add, newValue: value, newView: view, newViewIndex: index)); + ev.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Add, true, newItem: (value, view), newStartingIndex: index)); + } + } + } + + internal static void InvokeOnAddRange(this ISynchronizedView collection, ref int filteredCount, NotifyViewChangedEventHandler? ev, ReadOnlySpan values, ReadOnlySpan views, int index) + { + var isMatch = collection.Filter.IsMatch(value); + if (isMatch) + { + filteredCount++; + if (ev != null) + { + ev.Invoke(new SynchronizedViewChangedEventArgs(NotifyCollectionChangedAction.Add, false, newValues: values, newViews: views, newStartingIndex: index)); } } }