Skip to content

Commit a95487a

Browse files
committed
simplified view building on source chagne
1 parent 5ca5369 commit a95487a

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

src/ItemsSource/CollectionView.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private void OnFilterDescriptionsCollectionChanged(object? sender, NotifyCollect
4848
if (e.Action == NotifyCollectionChangedAction.Reset)
4949
HandleSourceChanged();
5050
else
51-
HandleFilterChanged();
51+
HandleFilterChanged();
5252
}
5353

5454
/// <summary>
@@ -61,7 +61,7 @@ private void OnSortDescriptionsCollectionChanged(object? sender, NotifyCollectio
6161
if (e.Action == NotifyCollectionChangedAction.Reset)
6262
HandleSourceChanged();
6363
else
64-
HandleSortChanged();
64+
HandleSortChanged();
6565
}
6666

6767
/// <summary>
@@ -216,28 +216,21 @@ private void HandleSourceChanged()
216216

217217
if (Source is not null)
218218
{
219-
if (FilterDescriptions.Any() || SortDescriptions.Any())
219+
if (FilterDescriptions.Count > 0)
220220
{
221221
foreach (var item in Source)
222222
{
223-
if (FilterDescriptions is not null && !FilterDescriptions.All(x => x.Predicate(item)))
224-
{
225-
continue;
226-
}
227-
228-
var targetIndex = _view.BinarySearch(item, this);
229-
if (targetIndex < 0)
230-
{
231-
targetIndex = ~targetIndex;
232-
}
233-
234-
_view.Insert(targetIndex, item);
223+
if (FilterDescriptions.All(x => x.Predicate(item)))
224+
_view.Add(item);
235225
}
236226
}
237227
else
238228
{
239229
_view.AddRange(_source.OfType<object>());
240230
}
231+
232+
if (SortDescriptions.Count > 0)
233+
_view.Sort(this);
241234
}
242235

243236
OnVectorChanged(new VectorChangedEventArgs(CollectionChange.Reset));

0 commit comments

Comments
 (0)