Skip to content

Commit

Permalink
Reduce allocations in NodeStateTable.GetPackedState (#72355)
Browse files Browse the repository at this point in the history
Boxing of the EntryState enum shows up in the RichCopyTest.CopyPlain test numbers as almost 1% of allocations. This code just needs to map EntryState values to a character for packing.
  • Loading branch information
ToddGrun authored Mar 1, 2024
1 parent d21bece commit cf2d9be
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,16 @@ public string GetPackedStates()
{
for (int i = 0; i < state.Count; i++)
{
pooled.Builder.Append(state.GetState(i).ToString()[0]);
var packedChar = state.GetState(i) switch
{
EntryState.Added => 'A',
EntryState.Removed => 'R',
EntryState.Modified => 'M',
EntryState.Cached => 'C',
_ => throw ExceptionUtilities.Unreachable(),
};

pooled.Builder.Append(packedChar);
}
pooled.Builder.Append(',');
}
Expand Down

0 comments on commit cf2d9be

Please sign in to comment.