diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index 0b784e3..11b2750 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -528,7 +528,11 @@ impl FutureMoves { stack.extend(self.arena[idx].children.iter()); } - let mut index_map = vec![None; self.arena.len()]; + let mut index_map: HashMap< + usize, + usize, + BuildHasherDefault>, + > = HashMap::with_capacity_and_hasher(self.arena.len(), BuildHasherDefault::default()); let (indexes, moves): (Vec<(usize, usize)>, Vec) = retain .into_iter() @@ -541,7 +545,7 @@ impl FutureMoves { .unzip(); for (new_idx, old_idx) in indexes { - index_map[old_idx] = Some(new_idx); + index_map.insert(old_idx, new_idx); } self.arena = moves @@ -549,13 +553,12 @@ impl FutureMoves { .map(|mut node| { node.parent = node .parent - .and_then(|parent| index_map.get(parent)) - .and_then(|&x| x); + .and_then(|parent| index_map.get(&parent).copied()); for c in node.children.as_mut_slice() { *c = index_map - .get(*c) - .and_then(|&x| x) + .get(c) + .copied() .expect("index_map should contain the child's index"); } @@ -563,7 +566,7 @@ impl FutureMoves { }) .collect(); - self.current_root = index_map[root]; + self.current_root = index_map.get(&root).copied(); } }