Skip to content

Commit

Permalink
Avoid delegate allocation in TraceSourceLoggerProvider.GetOrAddTraceS…
Browse files Browse the repository at this point in the history
…ource (#71134)

Every call to GetOrAddTraceSource was allocating a new delegate instance.
  • Loading branch information
stephentoub committed Jun 22, 2022
1 parent c1d4494 commit de078d1
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ public ILogger CreateLogger(string name)
return new TraceSourceLogger(GetOrAddTraceSource(name));
}

private DiagnosticsTraceSource GetOrAddTraceSource(string name)
{
return _sources.GetOrAdd(name, InitializeTraceSource);
}
private DiagnosticsTraceSource GetOrAddTraceSource(string name) =>
_sources.TryGetValue(name, out DiagnosticsTraceSource? source) ? source :
_sources.GetOrAdd(name, InitializeTraceSource(name));

private DiagnosticsTraceSource InitializeTraceSource(string traceSourceName)
{
Expand Down

0 comments on commit de078d1

Please sign in to comment.