From 86d44553215fca6f545f26169564b5a1b3dcdd16 Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Fri, 28 Feb 2025 21:14:37 -0500 Subject: [PATCH] improve pruning tree indexing logic --- src/logic/future_moves.rs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/logic/future_moves.rs b/src/logic/future_moves.rs index a8bf47c..be1241c 100644 --- a/src/logic/future_moves.rs +++ b/src/logic/future_moves.rs @@ -442,22 +442,15 @@ impl FutureMoves { self.arena = moves .into_iter() .map(|mut node| { - if let Some(parent) = node.parent.as_mut() { - if let Some(new_parent) = index_map[*parent] { - *parent = new_parent; - } else { - // make sure we don't have dangling parents - node.parent = None; - } - } + node.parent = node + .parent + .and_then(|parent| index_map.get(parent).and_then(|&x| x)); for c in node.children.as_mut_slice() { - debug_assert_ne!( - index_map.get(*c).and_then(|&x| x), - None, - "index_map should contain the child's index" - ); - *c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() }; + *c = index_map + .get(*c) + .and_then(|&x| x) + .expect("index_map should contain the child's index"); } node