Skip to content

Commit

Permalink
Minor performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Apr 27, 2024
1 parent 31610e7 commit 6065a60
Show file tree
Hide file tree
Showing 16 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion readme/FuncDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ partial class Func
public partial Benchmarks.Model.CompositionRoot TestPureDIByCR()
{
Func<Benchmarks.Model.IService3> perBlock10_Func = new Func<Benchmarks.Model.IService3>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_1 = new Benchmarks.Model.Service3(new Benchmarks.Model.Service4(), new Benchmarks.Model.Service4());
Expand Down
2 changes: 1 addition & 1 deletion readme/async-disposable-scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ partial class Composition: IDisposable, IAsyncDisposable
{
var perResolve43_Func = default(Func<Session>);
perResolve43_Func = new Func<Session>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
Composition transient2_Composition = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/auto-scoped.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ partial class Composition
{
var perResolve43_Func = default(Func<IService>);
perResolve43_Func = new Func<IService>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
Composition transient2_Composition = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/func-with-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ partial class Composition
{
var perResolve39_Func = default(Func<IDependency>);
perResolve39_Func = new Func<IDependency>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_1 = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/func.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ partial class Composition
{
var perResolve39_Func = default(Func<IDependency>);
perResolve39_Func = new Func<IDependency>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_1 = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/lazy.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ partial class Composition
{
var perResolve40_Func = default(Func<IDependency>);
perResolve40_Func = new Func<IDependency>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_1 = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/manually-started-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ partial class Composition
{
var perResolve42_Func = default(Func<IDependency>);
perResolve42_Func = new Func<IDependency>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_1 = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/perblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ partial class Composition
{
var perResolve43_Func = default(Func<(IDependency dep3, IDependency dep4)>);
perResolve43_Func = new Func<(IDependency dep3, IDependency dep4)>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
Dependency perBlock4_Dependency = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/perresolve.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ partial class Composition
var perResolve36_Dependency = default(Dependency);
var perResolve43_Func = default(Func<(IDependency dep3, IDependency dep4)>);
perResolve43_Func = new Func<(IDependency dep3, IDependency dep4)>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
if (perResolve36_Dependency == null)
Expand Down
2 changes: 1 addition & 1 deletion readme/scope.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ partial class Composition: IDisposable
{
var perResolve43_Func = default(Func<Session>);
perResolve43_Func = new Func<Session>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
Composition transient2_Composition = this;
Expand Down
2 changes: 1 addition & 1 deletion readme/task.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ partial class Composition
perBlock2_TaskFactory = new TaskFactory<IDependency>(cancellationToken_1, taskCreationOptions_2, taskContinuationOptions_3, taskScheduler_4);
}
perResolve42_Func = new Func<IDependency>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var value_5 = new Dependency();
Expand Down
2 changes: 1 addition & 1 deletion readme/tracking-async-disposable-instances-in-delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ partial class Composition
{
var perResolve39_Func = default(Func<Owned<IDependency>>);
perResolve39_Func = new Func<Owned<IDependency>>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var accumulator38 = new Owned();
Expand Down
2 changes: 1 addition & 1 deletion readme/tracking-disposable-instances-in-delegates.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ partial class Composition
{
var perResolve39_Func = default(Func<Owned<IDependency>>);
perResolve39_Func = new Func<Owned<IDependency>>(
[MethodImpl((MethodImplOptions)768)]
[MethodImpl((MethodImplOptions)256)]
() =>
{
var accumulator38 = new Owned();
Expand Down
2 changes: 1 addition & 1 deletion src/Pure.DI.Core/Core/Code/FactoryRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal sealed class FactoryRewriter(
SyntaxFactory.AttributeArgument(
SyntaxFactory.CastExpression(
SyntaxFactory.ParseTypeName(Names.MethodImplOptions),
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0x300)))))))
SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(0x100)))))))
.WithTrailingTrivia(SyntaxTriviaList.Create(SyntaxFactory.SyntaxTrivia(SyntaxKind.WhitespaceTrivia, " ")));

private static readonly IdentifierNameSyntax InjectionMarkerExpression = SyntaxFactory.IdentifierName(Names.InjectionMarker);
Expand Down
6 changes: 3 additions & 3 deletions src/Pure.DI.MS/any/Pure.DI/MS/ServiceCollectionFactory.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ from ctor in typeof(ServiceDescriptor).GetConstructors(BindingFlags.Instance | B
/// <param name="resolver">Instance resolver.</param>
/// <param name="tag">The resolving tag.</param>
/// <typeparam name="TContract">The type of object that the resolver returns.</typeparam>
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
public void AddResolver<TContract>(IResolver<TComposition, TContract> resolver, object tag = default)
{
_resolvers.Add(new InstanceResolver(typeof(TContract), (IResolver<TComposition, object>)resolver, tag));
Expand All @@ -92,7 +92,7 @@ public void AddResolver<TContract>(IResolver<TComposition, TContract> resolver,
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP || NET40_OR_GREATER || NET
[global::System.Diagnostics.Contracts.Pure]
#endif
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
public IServiceCollection CreateServiceCollection(TComposition composition)
{
return new ServiceCollection().Add(CreateDescriptors(composition));
Expand All @@ -103,7 +103,7 @@ public IServiceCollection CreateServiceCollection(TComposition composition)
/// </summary>
/// <param name="composition">An instance of composition.</param>
/// <returns>A enumeration of <see cref="Microsoft.Extensions.DependencyInjection.ServiceDescriptor"/>.</returns>
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
private IEnumerable<ServiceDescriptor> CreateDescriptors(TComposition composition)
{
return _resolvers.Select(resolver => ServiceDescriptorProvider(composition, resolver));
Expand Down
9 changes: 4 additions & 5 deletions src/Pure.DI.MS/any/Pure.DI/MS/ServiceProviderFactory.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,21 @@ private static void HintsSetup() =>
#if NETSTANDARD2_0_OR_GREATER || NETCOREAPP || NET40_OR_GREATER || NET
[global::System.Diagnostics.Contracts.Pure]
#endif
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
protected static IServiceCollection CreateServiceCollection(TComposition composition)
{
return ServiceCollectionFactory.CreateServiceCollection(composition);
}

/// <inheritdoc />
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
public IServiceCollection CreateBuilder(IServiceCollection services)
{
// Registers composition roots as services in the service collection.
return services.Add(CreateServiceCollection((TComposition)this));
}

/// <inheritdoc />
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public IServiceProvider CreateServiceProvider(IServiceCollection services)
{
var serviceProvider = services.BuildServiceProvider();
Expand All @@ -111,7 +110,7 @@ public IServiceProvider CreateServiceProvider(IServiceCollection services)
/// <param name="lifetime">Dependency resolution lifetime.</param>
/// <typeparam name="T">Dependency resolution type.</typeparam>
/// <returns>Resolved dependency instance.</returns>
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
protected T OnCannotResolve<T>(object? tag, Lifetime lifetime)
{
return (T)(_serviceProvider ?? throw new InvalidOperationException("Not ready yet."))(typeof(T), tag)
Expand All @@ -127,7 +126,7 @@ protected T OnCannotResolve<T>(object? tag, Lifetime lifetime)
/// <param name="lifetime">The lifetime of the composition root.</param>
/// <typeparam name="TContract">The contract type of the composition root.</typeparam>
/// <typeparam name="T">The implementation type of the composition root.</typeparam>
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x100)]
protected static void OnNewRoot<TContract, T>(
IResolver<TComposition, TContract> resolver,
string name, object tag, Lifetime lifetime)
Expand Down

0 comments on commit 6065a60

Please sign in to comment.