Skip to content

Commit

Permalink
perf: Update DependencyPropertyCacheEntry comparer
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 8, 2021
1 parent ab54bd7 commit 0f723f3
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/Uno.UI/UI/Xaml/DependencyPropertyCacheEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
#nullable enable

using System;
using System.Collections;
using System.Text;
using Uno.Core.Comparison;

Expand All @@ -23,23 +25,28 @@ public PropertyCacheEntry(Type type, string name)

public static readonly Comparer DefaultComparer = new Comparer();

internal class Comparer : IEqualityComparer<PropertyCacheEntry>
internal class Comparer : IEqualityComparer
{
bool IEqualityComparer<PropertyCacheEntry>.Equals(PropertyCacheEntry left, PropertyCacheEntry right)
bool IEqualityComparer.Equals(object? x, object? y)
{
// This method assumes that there will never be null parameters, and that the Type and Name fields
// are never null.
return left.Type == right.Type
&& (
object.ReferenceEquals(left.Name, right.Name)
|| string.CompareOrdinal(left.Name, right.Name) == 0
);
if(x is PropertyCacheEntry left && y is PropertyCacheEntry right)
{
// This method assumes that there will never be null parameters, and that the Type and Name fields
// are never null.
return left.Type == right.Type
&& (
object.ReferenceEquals(left.Name, right.Name)
|| string.CompareOrdinal(left.Name, right.Name) == 0
);
}
else
{
return false;
}
}

int IEqualityComparer<PropertyCacheEntry>.GetHashCode(PropertyCacheEntry obj)
{
return obj.CachedHashCode;
}
int IEqualityComparer.GetHashCode(object? obj)
=> obj is PropertyCacheEntry entry ? entry.CachedHashCode : 0;
}
}

Expand Down

0 comments on commit 0f723f3

Please sign in to comment.