Skip to content

Commit

Permalink
Fixes breaking changes when using Span when building a map to resolve…
Browse files Browse the repository at this point in the history
… dependencies using "Resolve" methods. Micro performance improvements in "Resolve" methods.
  • Loading branch information
Nikolay Pyanikov committed Jul 28, 2023
1 parent 69d9de3 commit 8150f95
Show file tree
Hide file tree
Showing 54 changed files with 497 additions and 1,083 deletions.
7 changes: 3 additions & 4 deletions benchmarks/Pure.DI.Benchmarks/GetBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,14 @@ private static string Get(Type key)
private static string GetWhile(Type key)
{
int index = (int)(BucketSize * ((uint)RuntimeHelpers.GetHashCode(key) % Divisor));
var finish = index + BucketSize;
do
{
int finish = index + BucketSize;
do {
ref var pair = ref Pairs[index];
if (ReferenceEquals(pair.Key, key))
{
return pair.Value;
}
} while(++index < finish);
} while (++index < finish);

throw new InvalidOperationException();
}
Expand Down
2 changes: 1 addition & 1 deletion readme/Console.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The [project file](/samples/ShroedingersCat/ShroedingersCat.csproj) looks like t
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.5">
<PackageReference Include="Pure.DI" Version="2.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/ConsoleTopLevelStatements.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The [project file](/samples/ShroedingersCatTopLevelStatements/ShroedingersCatTop
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.5">
<PackageReference Include="Pure.DI" Version="2.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/WebAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ The [project file](/samples/WebAPI/WebAPI.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.5">
<PackageReference Include="Pure.DI" Version="2.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion readme/Wpf.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The [project file](/samples/WpfAppNetCore/WpfAppNetCore.csproj) looks like this:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pure.DI" Version="2.0.5">
<PackageReference Include="Pure.DI" Version="2.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
32 changes: 10 additions & 22 deletions readme/a-few-partial-classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -156,21 +150,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
32 changes: 10 additions & 22 deletions readme/advanced-interception.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,21 +196,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -221,21 +215,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
32 changes: 10 additions & 22 deletions readme/arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -179,21 +173,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
32 changes: 10 additions & 22 deletions readme/array.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -158,21 +152,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
32 changes: 10 additions & 22 deletions readme/auto-bindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -130,21 +124,15 @@ partial class Composition
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
32 changes: 10 additions & 22 deletions readme/child-composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,21 +155,15 @@ partial class Composition: System.IDisposable
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.Resolve(this);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root of type {type}.");
}
Expand All @@ -180,21 +174,15 @@ partial class Composition: System.IDisposable
[global::System.Runtime.CompilerServices.MethodImpl((global::System.Runtime.CompilerServices.MethodImplOptions)0x300)]
public object Resolve(global::System.Type type, object? tag)
{
int index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}

for (int i = index + 1; i < index + _bucketSizeM07D28di; i++)
{
pair = ref _bucketsM07D28di[i];
var index = (int)(_bucketSizeM07D28di * ((uint)global::System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(type) % 1));
var finish = index + _bucketSizeM07D28di;
do {
ref var pair = ref _bucketsM07D28di[index];
if (ReferenceEquals(pair.Key, type))
{
return pair.Value.ResolveByTag(this, tag);
}
}
} while (++index < finish);

throw new global::System.InvalidOperationException($"Cannot resolve composition root \"{tag}\" of type {type}.");
}
Expand Down
Loading

0 comments on commit 8150f95

Please sign in to comment.