]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Reduce some state handling allocs (#14301)
authormetalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Tue, 28 Feb 2023 16:05:29 +0000 (03:05 +1100)
committerGitHub <noreply@github.com>
Tue, 28 Feb 2023 16:05:29 +0000 (08:05 -0800)
Content.Shared/Doors/Systems/SharedDoorSystem.cs
Content.Shared/Mobs/Systems/MobStateSystem.cs
Content.Shared/Mobs/Systems/MobThresholdSystem.cs
Content.Shared/StepTrigger/Systems/StepTriggerSystem.cs

index c8db06b79236630544b044a1b1c5ba33d3dac482..bb590a32d971539e85af4593b5cec168dd780678 100644 (file)
@@ -108,9 +108,10 @@ public abstract class SharedDoorSystem : EntitySystem
         if (args.Current is not DoorComponentState state)
             return;
 
-        if (!door.CurrentlyCrushing.Equals(state.CurrentlyCrushing))
+        if (!door.CurrentlyCrushing.SetEquals(state.CurrentlyCrushing))
         {
-            door.CurrentlyCrushing = new(state.CurrentlyCrushing);
+            door.CurrentlyCrushing.Clear();
+            door.CurrentlyCrushing.UnionWith(state.CurrentlyCrushing);
         }
 
         door.State = state.DoorState;
index 4be7715a9895494ba72e27395900e8e188deffe1..ad2de1c80137fe9ab3587062e8127f6576e72bd7 100644 (file)
@@ -104,7 +104,12 @@ public partial class MobStateSystem : EntitySystem
             return;
 
         component.CurrentState = state.CurrentState;
-        component.AllowedStates = new HashSet<MobState>(state.AllowedStates);
+
+        if (!component.AllowedStates.SetEquals(state.AllowedStates))
+        {
+            component.AllowedStates.Clear();
+            component.AllowedStates.UnionWith(state.AllowedStates);
+        }
     }
 
     private void OnGetComponentState(EntityUid uid, MobStateComponent component, ref ComponentGetState args)
index c84fd097d98d0659e433ea9970aa5f3c53f411ba..dabd998ebc6334e2ab2a9517bbb17a06219842cd 100644 (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;
     }
 
index 72415ed83945b4d126223de4cfb2f0f8a451148e..b6398ca21db6204fa5ac2bca579a8c877c297434 100644 (file)
@@ -150,11 +150,17 @@ public sealed class StepTriggerSystem : EntitySystem
         component.IntersectRatio = state.IntersectRatio;
         component.Active = state.Active;
 
-        component.CurrentlySteppedOn.Clear();
-        component.Colliding.Clear();
+        if (!component.CurrentlySteppedOn.SetEquals(state.CurrentlySteppedOn))
+        {
+            component.CurrentlySteppedOn.Clear();
+            component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
+        }
 
-        component.CurrentlySteppedOn.UnionWith(state.CurrentlySteppedOn);
-        component.Colliding.UnionWith(state.Colliding);
+        if (!component.Colliding.SetEquals(state.Colliding))
+        {
+            component.Colliding.Clear();
+            component.Colliding.UnionWith(state.Colliding);
+        }
 
         if (component.Colliding.Count > 0)
         {