From 60536118185dc6584f8d5bed7d8054d1193624fb Mon Sep 17 00:00:00 2001 From: mnmaita <47983254+mnmaita@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:48:59 +0200 Subject: [PATCH 1/2] Replaces Iterator with slice in trigger_observers --- crates/bevy_ecs/src/world/deferred_world.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/bevy_ecs/src/world/deferred_world.rs b/crates/bevy_ecs/src/world/deferred_world.rs index cf2bb7c2cd499..92d953f3adbcc 100644 --- a/crates/bevy_ecs/src/world/deferred_world.rs +++ b/crates/bevy_ecs/src/world/deferred_world.rs @@ -370,13 +370,13 @@ impl<'w> DeferredWorld<'w> { &mut self, event: ComponentId, entity: Entity, - components: impl Iterator, + components: &[ComponentId], ) { Observers::invoke::<_>( self.reborrow(), event, entity, - components, + components.iter().copied(), &mut (), &mut false, ); From e32f51a27e45c66c4662d6dcf994328cdc1babd1 Mon Sep 17 00:00:00 2001 From: mnmaita <47983254+mnmaita@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:09:06 +0200 Subject: [PATCH 2/2] Updates code to fit the new signature --- crates/bevy_ecs/src/bundle.rs | 14 +++++--------- crates/bevy_ecs/src/world/entity_ref.rs | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/crates/bevy_ecs/src/bundle.rs b/crates/bevy_ecs/src/bundle.rs index 30214f1c8ce5d..efb850db54b84 100644 --- a/crates/bevy_ecs/src/bundle.rs +++ b/crates/bevy_ecs/src/bundle.rs @@ -682,11 +682,7 @@ impl<'w> BundleInserter<'w> { add_bundle.mutated.iter().copied(), ); if archetype.has_replace_observer() { - deferred_world.trigger_observers( - ON_REPLACE, - entity, - add_bundle.mutated.iter().copied(), - ); + deferred_world.trigger_observers(ON_REPLACE, entity, &add_bundle.mutated); } } @@ -842,11 +838,11 @@ impl<'w> BundleInserter<'w> { unsafe { deferred_world.trigger_on_add(new_archetype, entity, add_bundle.added.iter().cloned()); if new_archetype.has_add_observer() { - deferred_world.trigger_observers(ON_ADD, entity, add_bundle.added.iter().cloned()); + deferred_world.trigger_observers(ON_ADD, entity, &add_bundle.added); } deferred_world.trigger_on_insert(new_archetype, entity, bundle_info.iter_components()); if new_archetype.has_insert_observer() { - deferred_world.trigger_observers(ON_INSERT, entity, bundle_info.iter_components()); + deferred_world.trigger_observers(ON_INSERT, entity, bundle_info.components()); } } @@ -959,11 +955,11 @@ impl<'w> BundleSpawner<'w> { unsafe { deferred_world.trigger_on_add(archetype, entity, bundle_info.iter_components()); if archetype.has_add_observer() { - deferred_world.trigger_observers(ON_ADD, entity, bundle_info.iter_components()); + deferred_world.trigger_observers(ON_ADD, entity, bundle_info.components()); } deferred_world.trigger_on_insert(archetype, entity, bundle_info.iter_components()); if archetype.has_insert_observer() { - deferred_world.trigger_observers(ON_INSERT, entity, bundle_info.iter_components()); + deferred_world.trigger_observers(ON_INSERT, entity, bundle_info.components()); } }; diff --git a/crates/bevy_ecs/src/world/entity_ref.rs b/crates/bevy_ecs/src/world/entity_ref.rs index a983d9314c31c..a039cb4a90f7c 100644 --- a/crates/bevy_ecs/src/world/entity_ref.rs +++ b/crates/bevy_ecs/src/world/entity_ref.rs @@ -1224,11 +1224,19 @@ impl<'w> EntityWorldMut<'w> { unsafe { deferred_world.trigger_on_replace(archetype, self.entity, archetype.components()); if archetype.has_replace_observer() { - deferred_world.trigger_observers(ON_REPLACE, self.entity, archetype.components()); + deferred_world.trigger_observers( + ON_REPLACE, + self.entity, + &archetype.components().collect::>(), + ); } deferred_world.trigger_on_remove(archetype, self.entity, archetype.components()); if archetype.has_remove_observer() { - deferred_world.trigger_observers(ON_REMOVE, self.entity, archetype.components()); + deferred_world.trigger_observers( + ON_REMOVE, + self.entity, + &archetype.components().collect::>(), + ); } } @@ -1435,11 +1443,11 @@ unsafe fn trigger_on_replace_and_on_remove_hooks_and_observers( ) { deferred_world.trigger_on_replace(archetype, entity, bundle_info.iter_components()); if archetype.has_replace_observer() { - deferred_world.trigger_observers(ON_REPLACE, entity, bundle_info.iter_components()); + deferred_world.trigger_observers(ON_REPLACE, entity, bundle_info.components()); } deferred_world.trigger_on_remove(archetype, entity, bundle_info.iter_components()); if archetype.has_remove_observer() { - deferred_world.trigger_observers(ON_REMOVE, entity, bundle_info.iter_components()); + deferred_world.trigger_observers(ON_REMOVE, entity, bundle_info.components()); } }