From 225d6a138f8f5be92ef42ce146a76d4c43f60f72 Mon Sep 17 00:00:00 2001 From: Marc Parenteau Date: Thu, 4 Nov 2021 20:55:28 +0000 Subject: [PATCH] remove Box from ExclusiveSystemFn (#3063) Minor refactor to remove the boxing of the function pointer stored in ExclusiveSystemFn. --- crates/bevy_ecs/src/schedule/system_descriptor.rs | 5 ++++- crates/bevy_ecs/src/system/exclusive_system.rs | 15 +++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/crates/bevy_ecs/src/schedule/system_descriptor.rs b/crates/bevy_ecs/src/schedule/system_descriptor.rs index 74a3963ca2..6f470076bf 100644 --- a/crates/bevy_ecs/src/schedule/system_descriptor.rs +++ b/crates/bevy_ecs/src/schedule/system_descriptor.rs @@ -78,7 +78,10 @@ impl IntoSystemDescriptor<()> for ExclusiveSystemDescriptor { } } -impl IntoSystemDescriptor<()> for ExclusiveSystemFn { +impl IntoSystemDescriptor<()> for ExclusiveSystemFn +where + F: FnMut(&mut crate::prelude::World) + Send + Sync + 'static, +{ fn into_descriptor(self) -> SystemDescriptor { new_exclusive_descriptor(Box::new(self)).into_descriptor() } diff --git a/crates/bevy_ecs/src/system/exclusive_system.rs b/crates/bevy_ecs/src/system/exclusive_system.rs index 42dfb16c4c..1d7902650d 100644 --- a/crates/bevy_ecs/src/system/exclusive_system.rs +++ b/crates/bevy_ecs/src/system/exclusive_system.rs @@ -15,13 +15,16 @@ pub trait ExclusiveSystem: Send + Sync + 'static { fn check_change_tick(&mut self, change_tick: u32); } -pub struct ExclusiveSystemFn { - func: Box, +pub struct ExclusiveSystemFn { + func: F, name: Cow<'static, str>, last_change_tick: u32, } -impl ExclusiveSystem for ExclusiveSystemFn { +impl ExclusiveSystem for ExclusiveSystemFn +where + F: FnMut(&mut World) + Send + Sync + 'static, +{ fn name(&self) -> Cow<'static, str> { self.name.clone() } @@ -52,13 +55,13 @@ pub trait IntoExclusiveSystem { fn exclusive_system(self) -> SystemType; } -impl IntoExclusiveSystem<&mut World, ExclusiveSystemFn> for F +impl IntoExclusiveSystem<&mut World, ExclusiveSystemFn> for F where F: FnMut(&mut World) + Send + Sync + 'static, { - fn exclusive_system(self) -> ExclusiveSystemFn { + fn exclusive_system(self) -> ExclusiveSystemFn { ExclusiveSystemFn { - func: Box::new(self), + func: self, name: core::any::type_name::().into(), last_change_tick: 0, }