From 2ca008af9be3dc002ee10ad250df0178afbaff26 Mon Sep 17 00:00:00 2001 From: SvenTS <73037851+SvenTS@users.noreply.github.com> Date: Sat, 21 Nov 2020 17:56:30 +0100 Subject: [PATCH] Remove unnecessary reverse --- crates/bevy_ui/src/update.rs | 61 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/crates/bevy_ui/src/update.rs b/crates/bevy_ui/src/update.rs index 18daee4efabbec..cd5bb4356e56c1 100644 --- a/crates/bevy_ui/src/update.rs +++ b/crates/bevy_ui/src/update.rs @@ -16,7 +16,6 @@ pub fn ui_z_system( .iter() .map(|e| (e, UI_BASE_DEPTH)) .collect::>(); - node_stack.reverse(); while let Some((node, parent_global_z)) = node_stack.pop() { current_global_z += UI_Z_STEP; let local_z = current_global_z - parent_global_z; @@ -58,7 +57,18 @@ mod tests { let mut commands = Commands::default(); commands.set_entity_reserver(world.get_entity_reserver()); - commands.spawn(node_with_transform("0")); + commands + .spawn(node_without_transform("0")) + .with_children(|parent| { + parent + .spawn(node_with_transform("0-0")) + .with_children(|_parent| ()); + parent + .spawn(node_with_transform("0-1")) + .with_children(|parent| { + parent.spawn(node_with_transform("0-1-0")); + }); + }); commands .spawn(node_with_transform("1")) @@ -83,19 +93,8 @@ mod tests { }); parent.spawn(node_with_transform("1-3")); }); + commands.spawn(node_with_transform("2")); - commands - .spawn(node_without_transform("2")) - .with_children(|parent| { - parent - .spawn(node_with_transform("2-0")) - .with_children(|_parent| ()); - parent - .spawn(node_with_transform("2-1")) - .with_children(|parent| { - parent.spawn(node_with_transform("2-1-0")); - }); - }); commands.apply(&mut world, &mut resources); let mut schedule = Schedule::default(); @@ -110,23 +109,23 @@ mod tests { .collect::>(); actual_result.sort_unstable_by_key(|(name, _)| name.clone()); let expected_result = vec![ - ("0".to_owned(), 1), // total_depth 1 - ("1".to_owned(), 2), // total_depth 2 - ("1-0".to_owned(), 1), // total_depth 3 - ("1-0-0".to_owned(), 1), // total_depth 4 - // 1-0-1 has no transform total_depth 5 - ("1-0-2".to_owned(), 3), // total_depth 6 - ("1-1".to_owned(), 5), // total_depth 7 - // 1-2 has no transform total_depth 8 - ("1-2-0".to_owned(), 1), // total_depth 9 - ("1-2-1".to_owned(), 2), // total_depth 10 - ("1-2-2".to_owned(), 3), // total_depth 11 - ("1-2-3".to_owned(), 4), // total_depth 12 - ("1-3".to_owned(), 11), // total_depth 13 - // 2 has no transform total_depth 14 - ("2-0".to_owned(), 1), // total_depth 15 - ("2-1".to_owned(), 2), // total_depth 16 - ("2-1-0".to_owned(), 1), // total_depth 17 + // 0 has no transform total_depth 1 + ("0-0".to_owned(), 1), // total_depth 2 + ("0-1".to_owned(), 2), // total_depth 3 + ("0-1-0".to_owned(), 1), // total_depth 4 + ("1".to_owned(), 5), // total_depth 5 + ("1-0".to_owned(), 1), // total_depth 6 + ("1-0-0".to_owned(), 1), // total_depth 7 + // 1-0-1 has no transform total_depth 8 + ("1-0-2".to_owned(), 3), // total_depth 9 + ("1-1".to_owned(), 5), // total_depth 10 + // 1-2 has no transform total_depth 11 + ("1-2-0".to_owned(), 1), // total_depth 12 + ("1-2-1".to_owned(), 2), // total_depth 13 + ("1-2-2".to_owned(), 3), // total_depth 14 + ("1-2-3".to_owned(), 4), // total_depth 15 + ("1-3".to_owned(), 11), // total depth 16 + ("2".to_owned(), 17), // total_depth 17 ]; assert_eq!(actual_result, expected_result); }