Skip to content

Commit

Permalink
Make the type components cache factory even more lazy
Browse files Browse the repository at this point in the history
Follow up to dotnet#80726. Needed a bit more laziness to really get everything out of the picture.
  • Loading branch information
MichalStrehovsky committed Jan 19, 2023
1 parent 88ab5ba commit 52123e9
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public QueriedMemberList<M> GetQueriedMembers<M>(MemberPolicies<M> policies, str
PerNameQueryCache<M> unifier = Unsafe.As<PerNameQueryCache<M>>(obj);

// Set the policies if they're not set yet. See the comment on SetPolicies on why we do this for details.
unifier.SetPolicies(policies);
unifier.SetPolicies(policies, QueriedMemberList<M>.Create);

QueriedMemberList<M> result = unifier.GetOrAdd(name);
return result;
Expand Down Expand Up @@ -127,19 +127,21 @@ public PerNameQueryCache(RuntimeTypeInfo type, bool ignoreCase)
// purpose - the PerNameQueryCache instances are created eagerly, but not all apps might require
// MemberPolicies for all members. This allows us to delay creating the MemberPolicies instance
// until the need arises.
public void SetPolicies(MemberPolicies<M> policies)
public void SetPolicies(MemberPolicies<M> policies, Func<MemberPolicies<M>, RuntimeTypeInfo, string, bool, QueriedMemberList<M>> factory)
{
_policies = policies;
_factory = factory;
}

protected sealed override QueriedMemberList<M> Factory(string key)
{
QueriedMemberList<M> result = QueriedMemberList<M>.Create(_policies, _type, key, ignoreCase: _ignoreCase);
QueriedMemberList<M> result = _factory(_policies, _type, key, _ignoreCase);
result.Compact();
return result;
}

private MemberPolicies<M> _policies;
private Func<MemberPolicies<M>, RuntimeTypeInfo, string, bool, QueriedMemberList<M>> _factory;
private readonly RuntimeTypeInfo _type;
private readonly bool _ignoreCase;
}
Expand Down

0 comments on commit 52123e9

Please sign in to comment.