From 1262a9c6c9bd23c3cee85ce9c3de139c5974bbc5 Mon Sep 17 00:00:00 2001 From: reaperrr Date: Fri, 18 Jun 2021 18:32:00 +0200 Subject: [PATCH] Minor FlyIdle perf optimization None of these prerequisites change on the fly, so cache the result in the activity ctor. --- OpenRA.Mods.Common/Activities/Air/FlyIdle.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs index 1589854555..2988e1de40 100644 --- a/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs +++ b/OpenRA.Mods.Common/Activities/Air/FlyIdle.cs @@ -22,10 +22,12 @@ namespace OpenRA.Mods.Common.Activities readonly INotifyIdle[] tickIdles; readonly bool idleTurn; int remainingTicks; + bool isIdleTurner; public FlyIdle(Actor self, int ticks = -1, bool idleTurn = true) { aircraft = self.Trait(); + isIdleTurner = aircraft.Info.IdleSpeed > 0 || (!aircraft.Info.CanHover && aircraft.Info.IdleSpeed < 0); remainingTicks = ticks; this.idleTurn = idleTurn; @@ -48,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities foreach (var tickIdle in tickIdles) tickIdle.TickIdle(self); - if (aircraft.Info.IdleSpeed > 0 || (!aircraft.Info.CanHover && aircraft.Info.IdleSpeed < 0)) + if (isIdleTurner) { var speed = aircraft.Info.IdleSpeed < 0 ? aircraft.Info.Speed : aircraft.Info.IdleSpeed;