@@ -31,6 +31,12 @@ public sealed partial class DependencyProperty
31
31
private readonly static TypeToPropertiesDictionary _getPropertiesForType = new TypeToPropertiesDictionary ( ) ;
32
32
private readonly static NameToPropertyDictionary _getPropertyCache = new NameToPropertyDictionary ( ) ;
33
33
34
+ /// <summary>
35
+ /// A static <see cref="PropertyCacheEntry"/> used for lookups and avoid creating new instances. This assumes that uses are non-reentrant.
36
+ /// </summary>
37
+ private readonly static PropertyCacheEntry _searchPropertyCacheEntry = new ( ) ;
38
+
39
+
34
40
private readonly static FrameworkPropertiesForTypeDictionary _getFrameworkPropertiesForType = new FrameworkPropertiesForTypeDictionary ( ) ;
35
41
36
42
private readonly PropertyMetadata _ownerTypeMetadata ; // For perf consideration, we keep direct ref the metadata for the owner type
@@ -317,12 +323,11 @@ internal bool IsUnoType
317
323
/// <returns>A <see cref="DependencyProperty"/> instance, otherwise null it not found.</returns>
318
324
internal static DependencyProperty GetProperty ( Type type , string name )
319
325
{
320
- DependencyProperty result = null ;
321
- var key = new PropertyCacheEntry ( type , name ) ;
326
+ _searchPropertyCacheEntry . Update ( type , name ) ;
322
327
323
- if ( ! _getPropertyCache . TryGetValue ( key , out result ) )
328
+ if ( ! _getPropertyCache . TryGetValue ( _searchPropertyCacheEntry , out var result ) )
324
329
{
325
- _getPropertyCache . Add ( key , result = InternalGetProperty ( type , name ) ) ;
330
+ _getPropertyCache . Add ( _searchPropertyCacheEntry . Clone ( ) , result = InternalGetProperty ( type , name ) ) ;
326
331
}
327
332
328
333
return result ;
@@ -332,7 +337,9 @@ private static void ResetGetPropertyCache(Type ownerType, string name)
332
337
{
333
338
if ( _getPropertyCache . Count != 0 )
334
339
{
335
- _getPropertyCache . Remove ( new PropertyCacheEntry ( ownerType , name ) ) ;
340
+ _searchPropertyCacheEntry . Update ( ownerType , name ) ;
341
+
342
+ _getPropertyCache . Remove ( _searchPropertyCacheEntry ) ;
336
343
}
337
344
}
338
345
0 commit comments