From 4becb2c616b5a24cab41643a6cc6294ec0ecd27d Mon Sep 17 00:00:00 2001 From: Imbris Date: Tue, 25 Apr 2023 01:06:17 -0400 Subject: [PATCH] Refactor iteration over cardinals for bridges to explicitly check for the cardinal direction instead of using specific indices, performance seems roughly the same. --- world/src/civ/mod.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/world/src/civ/mod.rs b/world/src/civ/mod.rs index b9a2a31565..39d751cb26 100644 --- a/world/src/civ/mod.rs +++ b/world/src/civ/mod.rs @@ -1403,11 +1403,9 @@ fn walk_in_all_dirs( // Look for potential bridge spots in the cardinal directions if // `loc_suitable_for_wallking` was false for the adjacent chunk. - for i in 0..4 { - // These happen to be indices for dirs where: dir.x == 0 || dir.y == 0 - let i = i * 2; - if potential[i].is_none() { - let dir = NEIGHBORS[i]; + for (i, &dir) in NEIGHBORS.iter().enumerate() { + let is_cardinal_dir = dir.x == 0 || dir.y == 0; + if is_cardinal_dir && potential[i].is_none() { // if we can skip over unsuitable area with a bridge potential[i] = (4..=5).find_map(|i| { loc_suitable_for_walking(sim, a + dir * i)