From 6a8d53307062061c76001957ef0cfd3061618049 Mon Sep 17 00:00:00 2001 From: JoePfeiffer Date: Mon, 7 Mar 2022 09:59:14 -0700 Subject: [PATCH] Cache active motors instead of recalculating on each call --- .../rocketcomponent/FlightConfiguration.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java index 7cbd9f0bf..70f645ab1 100644 --- a/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java +++ b/core/src/net/sf/openrocket/rocketcomponent/FlightConfiguration.java @@ -63,6 +63,7 @@ public class FlightConfiguration implements FlightConfigurableParameter stages = new HashMap(); final protected HashMap motors = new HashMap(); + final private Collection activeMotors = new ArrayList(); private int boundsModID = -1; private BoundingBox cachedBounds = new BoundingBox(); @@ -499,18 +500,12 @@ public class FlightConfiguration implements FlightConfigurableParameter getActiveMotors() { - Collection activeMotors = new ArrayList(); - for( MotorConfiguration config : this.motors.values() ){ - if( isComponentActive( config.getMount() )){ - activeMotors.add( config ); - } - } return activeMotors; } private void updateMotors() { - this.motors.clear(); + motors.clear(); for ( RocketComponent comp : getActiveComponents() ){ if (( comp instanceof MotorMount )&&( ((MotorMount)comp).isMotorMount())){ @@ -520,10 +515,16 @@ public class FlightConfiguration implements FlightConfigurableParameter