Skip to content

Commit 934ca05

Browse files
committed
Avoid dependency on LINQ orderby iterators when building exception messsage
Saves about 2k compressed for Blazor default template
1 parent 202c9fd commit 934ca05

File tree

1 file changed

+6
-3
lines changed
  • src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup

1 file changed

+6
-3
lines changed

src/libraries/Microsoft.Extensions.DependencyInjection/src/ServiceLookup/CallSiteChain.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ private string CreateCircularDependencyExceptionMessage(Type type)
4747
return messageBuilder.ToString();
4848
}
4949

50-
private void AppendResolutionPath(StringBuilder builder, Type currentlyResolving = null)
50+
private void AppendResolutionPath(StringBuilder builder, Type currentlyResolving)
5151
{
52-
foreach (KeyValuePair<Type, ChainItemInfo> pair in _callSiteChain.OrderBy(p => p.Value.Order))
52+
var ordered = new List<KeyValuePair<Type, ChainItemInfo>>(_callSiteChain);
53+
ordered.Sort((a, b) => a.Value.Order.CompareTo(b.Value.Order));
54+
55+
foreach (KeyValuePair<Type, ChainItemInfo> pair in ordered)
5356
{
5457
Type serviceType = pair.Key;
5558
Type implementationType = pair.Value.ImplementationType;
@@ -70,7 +73,7 @@ private void AppendResolutionPath(StringBuilder builder, Type currentlyResolving
7073
builder.Append(TypeNameHelper.GetTypeDisplayName(currentlyResolving));
7174
}
7275

73-
private struct ChainItemInfo
76+
private readonly struct ChainItemInfo
7477
{
7578
public int Order { get; }
7679
public Type ImplementationType { get; }

0 commit comments

Comments
 (0)