Skip to content

Commit

Permalink
Improved Resolve methods performance
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Apr 13, 2024
1 parent d757939 commit e2058a7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public CompositionCode Build(CompositionCode composition)

if (resolvers.Length > 0)
{
CreateObjectConflictsResolver(resolvers,
CreateObjectConflictsResolverMethod(resolvers,
$"{Names.SystemNamespace}Type type",
Names.ResolveMethodName,
"this",
Expand Down Expand Up @@ -126,7 +126,7 @@ public CompositionCode Build(CompositionCode composition)

if (resolvers.Length > 0)
{
CreateObjectConflictsResolver(resolvers,
CreateObjectConflictsResolverMethod(resolvers,
$"{Names.SystemNamespace}Type type, object? tag",
Names.ResolveByTagMethodName,
"this, tag",
Expand Down Expand Up @@ -191,7 +191,7 @@ private void CreateObjectResolverMethod(
{
code.AppendLine($"var index = (int)({Names.BucketSizeFieldName} * ((uint){Names.SystemNamespace}Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % {divisor}));");
code.AppendLine($"ref var pair = ref {Names.BucketsFieldName}[index];");
code.AppendLine($"return pair.Key == type ? pair.Value.{resolveMethodName}({resolveMethodArgs}) : Resolve{Names.Salt}(type, index);");
code.AppendLine($"return pair.Key == type ? pair.Value.{resolveMethodName}({resolveMethodArgs}) : Resolve{Names.Salt}(type, {(byTag ? "tag, " : "")}index);");
}
else
{
Expand All @@ -202,7 +202,7 @@ private void CreateObjectResolverMethod(
code.AppendLine("}");
}

private void CreateObjectConflictsResolver(
private static void CreateObjectConflictsResolverMethod(
IReadOnlyCollection<ResolverInfo> resolvers,
string methodArgs,
string resolveMethodName,
Expand Down

0 comments on commit e2058a7

Please sign in to comment.