Skip to content

Commit

Permalink
Check count before reusing batched items
Browse files Browse the repository at this point in the history
  • Loading branch information
jjonescz committed Mar 31, 2023
1 parent 968d97f commit 2984b5f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Compilers/Core/Portable/SourceGeneration/Nodes/BatchNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ public NodeStateTable<ImmutableArray<TInput>> UpdateStateTable(DriverStateTable.
{
newTable.AddEntry(sourceValues, EntryState.Added, stopwatch.Elapsed, sourceInputs, EntryState.Added);
}
else if (!sourceTable.IsCached || !newTable.TryUseCachedEntries(stopwatch.Elapsed, sourceInputs))
else if (!sourceTable.IsCached ||
GetTotalValueCount(previousTable) != sourceValues.Length ||
!newTable.TryUseCachedEntries(stopwatch.Elapsed, sourceInputs))
{
if (!newTable.TryModifyEntry(sourceValues, _comparer, stopwatch.Elapsed, sourceInputs, EntryState.Modified))
{
Expand All @@ -141,6 +143,16 @@ public NodeStateTable<ImmutableArray<TInput>> UpdateStateTable(DriverStateTable.
}

return newTable.ToImmutableAndFree();

static int GetTotalValueCount(NodeStateTable<ImmutableArray<TInput>> table)
{
var count = 0;
foreach (var entry in table)
{
count += entry.Item.Length;
}
return count;
}
}

public void RegisterOutput(IIncrementalGeneratorOutputNode output) => _sourceNode.RegisterOutput(output);
Expand Down

0 comments on commit 2984b5f

Please sign in to comment.