Change to finding affordable buildings to avoid a resize
authorJustin Worthe <justin@worthe-it.co.za>
Thu, 31 May 2018 19:25:14 +0000 (21:25 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Thu, 31 May 2018 19:25:14 +0000 (21:25 +0200)
src/engine/mod.rs

index e9cafa4..75583e3 100644 (file)
@@ -271,10 +271,13 @@ impl GameState {
     }
 
     fn affordable_buildings(energy: u16, settings: &GameSettings) -> Vec<BuildingType> {
-        BuildingType::all().iter()
-            .filter(|&b| settings.building_settings(*b).price <= energy)
-            .cloned()
-            .collect()
+        let mut result = Vec::with_capacity(3);
+        for b in BuildingType::all().iter() {
+            if settings.building_settings(*b).price <= energy {
+                result.push(*b);
+            }
+        }
+        result
     }
 }