Skip to content

Commit

Permalink
perf: Use cached DependencyProperty comparer
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed May 19, 2021
1 parent 640a543 commit 6ef9e81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyObjectStore.Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public partial class DependencyObjectStore

private readonly object _gate = new object();

private readonly HashtableEx _childrenBindableMap = new HashtableEx();
private readonly HashtableEx _childrenBindableMap = new HashtableEx(DependencyPropertyComparer.Default);
private readonly List<object?> _childrenBindable = new List<object?>();

private bool _isApplyingTemplateBindings;
Expand Down
16 changes: 7 additions & 9 deletions src/Uno.UI/UI/Xaml/DependencyPropertyComparer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;

Expand All @@ -7,7 +8,7 @@ namespace Windows.UI.Xaml
/// <summary>
/// A dependency property comparer that assumes that instances are unique and that the hash code will never change.
/// </summary>
internal class DependencyPropertyComparer : IEqualityComparer<DependencyProperty>
internal class DependencyPropertyComparer : IEqualityComparer<DependencyProperty>, IEqualityComparer
{
/// <summary>
/// Gets the default instance of DependencyPropertyComparer. This class has no state and cannot be created.
Expand All @@ -18,14 +19,11 @@ private DependencyPropertyComparer()
{
}

public bool Equals(DependencyProperty x, DependencyProperty y)
{
return object.ReferenceEquals(x, y);
}
public bool Equals(DependencyProperty x, DependencyProperty y) => object.ReferenceEquals(x, y);

public int GetHashCode(DependencyProperty obj)
{
return obj.CachedHashCode;
}
public int GetHashCode(DependencyProperty obj) => obj.CachedHashCode;

bool IEqualityComparer.Equals(object x, object y) => object.ReferenceEquals(x, y);
int IEqualityComparer.GetHashCode(object obj) => obj is DependencyProperty dp ? dp.CachedHashCode : 0;
}
}

0 comments on commit 6ef9e81

Please sign in to comment.