Permalink
Browse files

ApplyPropertiesVisitor - added a static cache for BindableProperty re…

…flection

It seemed that Type.GetFields() was called ALOT
  • Loading branch information...
Jonathan Peppers
Jonathan Peppers committed Jun 29, 2016
1 parent 743c1b3 commit 798b0c15e89d2273ca17acb9617e9d245d93d7ad
Showing with 10 additions and 2 deletions.
  1. +10 −2 Xamarin.Forms.Xaml/ApplyPropertiesVisitor.cs
@@ -19,6 +19,7 @@ internal class ApplyPropertiesVisitor : IXamlNodeVisitor
XmlName.xFactoryMethod,
XmlName.xName
};
static readonly ConcurrentDictionary<Type, Dictionary<string, FieldInfo>> _bindablePropertiesCache = new ConcurrentDictionary<Type, Dictionary<string, FieldInfo>>();
public ApplyPropertiesVisitor(HydratationContext context, bool stopOnResourceDictionary = false)
{
@@ -273,8 +274,15 @@ static string GetContentPropertyName(IEnumerable<CustomAttributeData> attributes
static BindableProperty GetBindableProperty(Type elementType, string localName, IXmlLineInfo lineInfo,
bool throwOnError = false)
{
var bindableFieldInfo =
elementType.GetFields().FirstOrDefault(fi => fi.Name == localName + "Property" && fi.IsStatic && fi.IsPublic);
Dictionary<string, FieldInfo> fields;
if (!_bindablePropertiesCache.TryGetValue(elementType, out fields))
{
_bindablePropertiesCache[elementType] =
fields = elementType.GetFields().Where(fi => fi.Name.EndsWith("Property", StringComparison.Ordinal) && fi.IsStatic && fi.IsPublic).ToDictionary(fi => fi.Name);
}
FieldInfo bindableFieldInfo;
fields.TryGetValue(localName + "Property", out bindableFieldInfo);
Exception exception = null;
if (exception == null && bindableFieldInfo == null)

0 comments on commit 798b0c1

Please sign in to comment.