Improved perf of removing item from unoccupied cells list
authorJustin Worthe <justin@worthe-it.co.za>
Wed, 16 May 2018 22:01:52 +0000 (00:01 +0200)
committerJustin Worthe <justin@worthe-it.co.za>
Wed, 16 May 2018 22:01:52 +0000 (00:01 +0200)
src/engine/mod.rs

index 227a7f6..6626c0d 100644 (file)
@@ -165,7 +165,9 @@ impl GameState {
                     player.energy_generated += building.energy_generated_per_turn;
                     buildings.push(building);
                 }
-                unoccupied_cells.retain(|&pos| pos != p);
+
+                let to_remove_index = unoccupied_cells.iter().position(|&pos| pos == p).unwrap();
+                unoccupied_cells.swap_remove(to_remove_index);
             },
         }
     }