Skip to content

Commit

Permalink
perf: Improve name to DependencyProperty lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 8, 2021
1 parent 292522c commit 4bce59b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
55 changes: 55 additions & 0 deletions src/Uno.UI/UI/Xaml/DependencyProperty.Dictionary.NameToProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Windows.UI.Xaml;
using Uno.Extensions;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using Uno;
using System.Threading;
using Uno.Collections;

#if XAMARIN_ANDROID
using _View = Android.Views.View;
#elif XAMARIN_IOS_UNIFIED
using _View = UIKit.UIView;
#else
using _View = Windows.UI.Xaml.UIElement;
#endif

namespace Windows.UI.Xaml
{
public sealed partial class DependencyProperty
{
private class NameToPropertyDictionary
{
private readonly HashtableEx _entries = new HashtableEx(PropertyCacheEntry.DefaultComparer);

internal bool TryGetValue(PropertyCacheEntry key, out DependencyProperty? result)
{
if (_entries.TryGetValue(key, out var value))
{
result = (DependencyProperty)value!;

return true;
}

result = null;
return false;
}

internal void Add(PropertyCacheEntry key, DependencyProperty dependencyProperty)
=> _entries.Add(key, dependencyProperty);

internal void Remove(PropertyCacheEntry propertyCacheEntry)
=> _entries.Remove(propertyCacheEntry);

internal int Count => _entries.Count;

internal void Clear() => _entries.Clear();
}
}
}
2 changes: 1 addition & 1 deletion src/Uno.UI/UI/Xaml/DependencyProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static Dictionary<Type, Dictionary<string, DependencyProperty>> _registr
= new Dictionary<Type, Dictionary<string, DependencyProperty>>(Uno.Core.Comparison.FastTypeComparer.Default);

private readonly static Dictionary<Type, DependencyProperty[]> _getPropertiesForType = new Dictionary<Type, DependencyProperty[]>(Uno.Core.Comparison.FastTypeComparer.Default);
private readonly static Dictionary<PropertyCacheEntry, DependencyProperty> _getPropertyCache = new Dictionary<PropertyCacheEntry, DependencyProperty>(PropertyCacheEntry.DefaultComparer);
private readonly static NameToPropertyDictionary _getPropertyCache = new NameToPropertyDictionary();

private readonly static Dictionary<CachedTuple<Type, FrameworkPropertyMetadataOptions>, DependencyProperty[]> _getFrameworkPropertiesForType = new Dictionary<CachedTuple<Type, FrameworkPropertyMetadataOptions>, DependencyProperty[]>(CachedTuple<Type, FrameworkPropertyMetadataOptions>.Comparer);
private readonly static Dictionary<Type, DependencyProperty[]> _getDependencyObjectPropertiesForType = new Dictionary<Type, DependencyProperty[]>(Uno.Core.Comparison.FastTypeComparer.Default);
Expand Down

0 comments on commit 4bce59b

Please sign in to comment.