Reduce some state handling allocs (#14301)

This commit is contained in:
metalgearsloth
2023-03-01 03:05:29 +11:00
committed by GitHub
parent 644e2e2d60
commit b9a805b352
4 changed files with 30 additions and 8 deletions

View File

@@ -340,7 +340,17 @@ public sealed class MobThresholdSystem : EntitySystem
if (args.Current is not MobThresholdComponentState state)
return;
component.Thresholds = new SortedDictionary<FixedPoint2, MobState>(state.Thresholds);
if (component.Thresholds.Count != state.Thresholds.Count ||
!component.Thresholds.SequenceEqual(state.Thresholds))
{
component.Thresholds.Clear();
foreach (var threshold in state.Thresholds)
{
component.Thresholds.Add(threshold.Key, threshold.Value);
}
}
component.CurrentThresholdState = state.CurrentThresholdState;
}