Skip to content

Commit

Permalink
perf: FrameworkProperties for type performance
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Apr 8, 2021
1 parent 8b88c0b commit 366d36e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#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;

using _Key = Uno.CachedTuple<System.Type, Windows.UI.Xaml.FrameworkPropertyMetadataOptions>;

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

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

return true;
}

result = null;
return false;
}

internal void Add(_Key key, DependencyProperty[] value)
=> _entries.Add(key, value);

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 @@ -32,7 +32,7 @@ public sealed partial class DependencyProperty
private readonly static TypeToPropertiesDictionary _getPropertiesForType = new TypeToPropertiesDictionary();
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 FrameworkPropertiesForTypeDictionary _getFrameworkPropertiesForType = new FrameworkPropertiesForTypeDictionary();

private readonly PropertyMetadata _ownerTypeMetadata; // For perf consideration, we keep direct ref the metadata for the owner type
private readonly PropertyMetadataDictionary _metadata = new PropertyMetadataDictionary();
Expand Down

0 comments on commit 366d36e

Please sign in to comment.