Skip to content

Commit

Permalink
remove Box from ExclusiveSystemFn (#3063)
Browse files Browse the repository at this point in the history
Minor refactor to remove the boxing of the function pointer stored in ExclusiveSystemFn.
  • Loading branch information
R3DP1XL committed Nov 4, 2021
1 parent 91c3b21 commit 225d6a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion crates/bevy_ecs/src/schedule/system_descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ impl IntoSystemDescriptor<()> for ExclusiveSystemDescriptor {
}
}

impl IntoSystemDescriptor<()> for ExclusiveSystemFn {
impl<F> IntoSystemDescriptor<()> for ExclusiveSystemFn<F>
where
F: FnMut(&mut crate::prelude::World) + Send + Sync + 'static,
{
fn into_descriptor(self) -> SystemDescriptor {
new_exclusive_descriptor(Box::new(self)).into_descriptor()
}
Expand Down
15 changes: 9 additions & 6 deletions crates/bevy_ecs/src/system/exclusive_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ pub trait ExclusiveSystem: Send + Sync + 'static {
fn check_change_tick(&mut self, change_tick: u32);
}

pub struct ExclusiveSystemFn {
func: Box<dyn FnMut(&mut World) + Send + Sync + 'static>,
pub struct ExclusiveSystemFn<F> {
func: F,
name: Cow<'static, str>,
last_change_tick: u32,
}

impl ExclusiveSystem for ExclusiveSystemFn {
impl<F> ExclusiveSystem for ExclusiveSystemFn<F>
where
F: FnMut(&mut World) + Send + Sync + 'static,
{
fn name(&self) -> Cow<'static, str> {
self.name.clone()
}
Expand Down Expand Up @@ -52,13 +55,13 @@ pub trait IntoExclusiveSystem<Params, SystemType> {
fn exclusive_system(self) -> SystemType;
}

impl<F> IntoExclusiveSystem<&mut World, ExclusiveSystemFn> for F
impl<F> IntoExclusiveSystem<&mut World, ExclusiveSystemFn<F>> for F
where
F: FnMut(&mut World) + Send + Sync + 'static,
{
fn exclusive_system(self) -> ExclusiveSystemFn {
fn exclusive_system(self) -> ExclusiveSystemFn<F> {
ExclusiveSystemFn {
func: Box::new(self),
func: self,
name: core::any::type_name::<F>().into(),
last_change_tick: 0,
}
Expand Down

0 comments on commit 225d6a1

Please sign in to comment.