Skip to content

Avoid delegate allocation to call ListCollectionView.PrepareComparer #6511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ internal GroupDescription GroupBy
ListCollectionView.PrepareComparer(
_groupBy.CustomSort,
_groupBy.SortDescriptionsInternal,
() =>
static state =>
{
for (CollectionViewGroupInternal group = this;
group != null;
group = group.Parent)
for (CollectionViewGroupInternal group = (CollectionViewGroupInternal)state;
group != null;
group = group.Parent)
{
CollectionViewGroupRoot root = group as CollectionViewGroupRoot;
if (root != null)
Expand All @@ -100,7 +100,7 @@ internal GroupDescription GroupBy
}
}
return null; // this should never happen - root should always be present
});
}, this);

if (oldIsBottomLevel != IsBottomLevel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,7 @@ internal bool HasSortDescriptions

// return an appropriate comparer. Common logic used by ListCollectionView
// and by CollectionViewGroupInternal.
internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionCollection sort, Func<CollectionView> lazyGetCollectionView)
internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionCollection sort, Func<object, CollectionView> lazyGetCollectionView, object state)
{
if (customSort != null)
{
Expand All @@ -2456,7 +2456,7 @@ internal static IComparer PrepareComparer(IComparer customSort, SortDescriptionC

if (sort != null && sort.Count > 0)
{
CollectionView view = lazyGetCollectionView();
CollectionView view = lazyGetCollectionView(state);
Debug.Assert(view != null, "lazyGetCollectionView should not return null");

if (view.SourceCollection != null)
Expand Down Expand Up @@ -2895,7 +2895,7 @@ private void AdjustCurrencyForReplace(int index)
private void PrepareShaping()
{
// sort: prepare the comparer
ActiveComparer = ListCollectionView.PrepareComparer(_customSort, _sort, () => { return this; });
ActiveComparer = PrepareComparer(_customSort, _sort, static state => (ListCollectionView)state, this);

// filter: prepare the Predicate<object> filter
ActiveFilter = Filter;
Expand Down