diff options
author | Justin Worthe <justin@worthe-it.co.za> | 2018-05-17 00:01:52 +0200 |
---|---|---|
committer | Justin Worthe <justin@worthe-it.co.za> | 2018-05-17 00:01:52 +0200 |
commit | ac2951451cc1fc26b6d8a7a0aa1267535b36b3d1 (patch) | |
tree | 93cb33cd998531889d3cebaf4a93774c4a4ab02d /src/engine/mod.rs | |
parent | 8c611df4d8bc412588b25ca09577827cc32971e9 (diff) |
Improved perf of removing item from unoccupied cells list
Diffstat (limited to 'src/engine/mod.rs')
-rw-r--r-- | src/engine/mod.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/engine/mod.rs b/src/engine/mod.rs index 227a7f6..6626c0d 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -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); }, } } |