Skip to content

Commit

Permalink
Avoid delegate allocation to call ListCollectionView.PrepareComparer (#…
Browse files Browse the repository at this point in the history
…6511)

Pass the required state is a a static object to be passed on to the delegate invocation.
  • Loading branch information
stephentoub authored Jul 21, 2022
1 parent 81ddc95 commit c8742b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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

1 comment on commit c8742b5

@DCLMEDIAINC
Copy link

@DCLMEDIAINC DCLMEDIAINC commented on c8742b5 Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

### test `

  • #deployment

`@DCLMEDIAINC

Please sign in to comment.