From e2058a7ea3b3901b6649cad697824e2210b1395e Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Sat, 13 Apr 2024 11:45:45 +0300 Subject: [PATCH] Improved Resolve methods performance --- src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs b/src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs index 4c3a8329..0d28617e 100644 --- a/src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs +++ b/src/Pure.DI.Core/Core/Code/ApiMembersBuilder.cs @@ -90,7 +90,7 @@ public CompositionCode Build(CompositionCode composition) if (resolvers.Length > 0) { - CreateObjectConflictsResolver(resolvers, + CreateObjectConflictsResolverMethod(resolvers, $"{Names.SystemNamespace}Type type", Names.ResolveMethodName, "this", @@ -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", @@ -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 { @@ -202,7 +202,7 @@ private void CreateObjectResolverMethod( code.AppendLine("}"); } - private void CreateObjectConflictsResolver( + private static void CreateObjectConflictsResolverMethod( IReadOnlyCollection resolvers, string methodArgs, string resolveMethodName,