Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations in code generated by Logging generators (#61162) #62011

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void GenStruct(LoggerMethod lm, string nestedIndentation)
{nestedIndentation}}}
");
_builder.Append($@"
{nestedIndentation}public static string Format(__{lm.Name}Struct state, global::System.Exception? ex) => state.ToString();
{nestedIndentation}public static readonly global::System.Func<__{lm.Name}Struct, global::System.Exception?, string> Format = (state, ex) => state.ToString();
eerhardt marked this conversation as resolved.
Show resolved Hide resolved

{nestedIndentation}public int Count => {lm.TemplateParameters.Count + 1};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
return $"";
}

public static string Format(__M0Struct state, global::System.Exception? ex) => state.ToString();
public static readonly global::System.Func<__M0Struct, global::System.Exception?, string> Format = (state, ex) => state.ToString();

public int Count => 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
return $"M9";
}

public static string Format(__M9Struct state, global::System.Exception? ex) => state.ToString();
public static readonly global::System.Func<__M9Struct, global::System.Exception?, string> Format = (state, ex) => state.ToString();

public int Count => 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace Microsoft.Extensions.Logging.Generators.Tests.TestClasses
return $"M9 {p1} {p2} {p3} {p4} {p5} {p6} {p7}";
}

public static string Format(__Method9Struct state, global::System.Exception? ex) => state.ToString();
public static readonly global::System.Func<__Method9Struct, global::System.Exception?, string> Format = (state, ex) => state.ToString();

public int Count => 8;

Expand Down