Skip to content
Merged
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
Next Next commit
Source generator: avoid performance issue with syntax list containing…
… many items
  • Loading branch information
cston committed Mar 15, 2023
commit e7083bc7231ab3063b40a688166a5fe9696dad1a
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,40 @@ partial class C
Assert.Empty(diagnostics);
}

[Fact]
public static void SyntaxListWithManyItems()
{
const int nItems = 200000;
var builder = new System.Text.StringBuilder();
builder.AppendLine(
"""
using Microsoft.Extensions.Logging;
class Program
{
[LoggerMessage(EventId = 1, Level = LogLevel.Debug, Message = "M1")]
static partial void M1(ILogger logger)
{
""");
builder.AppendLine(" int[] values = new[] { ");
for (int i = 0; i < nItems; i++)
{
builder.Append("0, ");
}
builder.AppendLine("};");
builder.AppendLine("}");
builder.AppendLine("}");

string source = builder.ToString();
Compilation compilation = CompilationHelper.CreateCompilation(source);
LoggerMessageGenerator generator = new LoggerMessageGenerator();

(ImmutableArray<Diagnostic> diagnostics, _) =
RoslynTestUtils.RunGenerator(compilation, generator);

Assert.Single(diagnostics);
Assert.Equal(DiagnosticDescriptors.LoggingMethodHasBody.Id, diagnostics[0].Id);
}

private static async Task<IReadOnlyList<Diagnostic>> RunGenerator(
string code,
bool wrap = true,
Expand Down