Skip to content

Commit d52cb55

Browse files
authored
Avoid cost of star member access lookup if not registered (#789)
1 parent 80d3449 commit d52cb55

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Fluid/DefaultMemberAccessStrategy.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class DefaultMemberAccessStrategy : MemberAccessStrategy
1010
private readonly record struct Key(Type Type, string Name);
1111

1212
private Dictionary<Key, IMemberAccessor> _map = new();
13+
private bool _hasAllAccessors;
1314

1415
public override IMemberAccessor GetAccessor(Type type, string name)
1516
{
@@ -53,7 +54,8 @@ private IMemberAccessor GetAccessorUnlikely(Type type, string name)
5354
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5455
private bool TryGetAccessor(Type type, string name, out IMemberAccessor accessor)
5556
{
56-
return _map.TryGetValue(new Key(type, name), out accessor) || _map.TryGetValue(new Key(type, "*"), out accessor);
57+
return _map.TryGetValue(new Key(type, name), out accessor)
58+
|| (_hasAllAccessors && _map.TryGetValue(new Key(type, "*"), out accessor));
5759
}
5860

5961
public override void Register(Type type, IEnumerable<KeyValuePair<string, IMemberAccessor>> accessors)
@@ -74,6 +76,7 @@ public override void Register(Type type, IEnumerable<KeyValuePair<string, IMembe
7476

7577
foreach (var accessor in accessors)
7678
{
79+
_hasAllAccessors |= accessor.Key == "*";
7780
temp[new Key(type, accessor.Key)] = accessor.Value;
7881
}
7982

0 commit comments

Comments
 (0)