From c8bed70f793d9b597039c190e5283af3578d33eb Mon Sep 17 00:00:00 2001 From: Elliott Pierce Date: Wed, 29 Jan 2025 13:51:19 -0500 Subject: [PATCH] bit of polish --- crates/bevy_ecs/src/component.rs | 44 +++----------------------------- crates/bevy_ecs/src/world/mod.rs | 13 +++------- 2 files changed, 7 insertions(+), 50 deletions(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index cef6595d99c17..8f3de79b38692 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -2414,9 +2414,7 @@ impl Components { unsafe { self.full_unchecked() } } - /// Gets the metadata associated with the given component. - /// - /// This will return an incorrect result if `id` did not come from the same world as `self`. It may return `None` or a garbage value. + /// A version of [`ComponentsViewRef::get_info`] that doesn't always need to lock. #[inline] pub fn get_info(&self, id: ComponentId) -> Option> { if let Some(index_in_new) = id.0.checked_sub(self.cold.len()) { @@ -2434,7 +2432,7 @@ impl Components { } } - /// Gets the metadata associated with the given component. + /// A version of [`ComponentsViewRef::get_info_uchecked`] that doesn't always need to lock. /// /// # Safety /// @@ -2502,42 +2500,6 @@ impl Components { ) -> ComponentId { self.lock().register_resource_with_descriptor(descriptor) } - - /// Synchronized version of [`ComponentsViewInternal::register_required_components`]. - /// - /// # Safety - /// - /// See [`ComponentsViewInternal::register_required_components`]. - pub(crate) unsafe fn register_required_components_synced( - &self, - requiree: ComponentId, - required: ComponentId, - constructor: fn() -> R, - ) -> Result<(), RequiredComponentsError> { - self.lock() - .as_mut() - .register_required_components(requiree, required, constructor) - } - - // NOTE: This should maybe be private, but it is currently public so that `bevy_ecs_macros` can use it. - // We can't directly move this there either, because this uses `Components::get_required_by_mut`, - // which is private, and could be equally risky to expose to users. - /// Synchronized version of [`ComponentsView::register_required_components_manual`]. - #[doc(hidden)] - pub fn register_required_components_manual_synced( - &self, - required_components: &mut RequiredComponents, - constructor: fn() -> R, - inheritance_depth: u16, - recursion_check_stack: &mut Vec, - ) { - self.lock().register_required_components_manual::( - required_components, - constructor, - inheritance_depth, - recursion_check_stack, - ); - } } impl ComponentsView for Components { @@ -3309,7 +3271,7 @@ impl<'a> RequiredByStagedRef<'a> { // TODO: replace ComponentInfoRef with https://doc.rust-lang.org/std/sync/struct.MappedRwLockReadGuard.html when it is stableized. -/// A reference to a particular component's info. +/// A reference to a particular component's info that may or may not need to lock [`Componnets`]. pub enum ComponentInfoRef<'a> { /// the requested data was registered a while ago. Stored(&'a ComponentInfo), diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 1df55f08a1fc9..f861f4bba7e2b 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -511,23 +511,18 @@ impl World { &self, constructor: fn() -> R, ) -> Result<(), RequiredComponentsError> { - let requiree = self.components.register_component_synced::(); + let mut components = self.components().lock(); + let requiree = components.register_component::(); // TODO: Remove this panic and update archetype edges accordingly when required components are added if self.archetypes().component_index().contains_key(&requiree) { return Err(RequiredComponentsError::ArchetypeExists(requiree)); } - let required = self.components.register_component_synced::(); + let required = components.register_component::(); // SAFETY: We just created the `required` and `requiree` components. - unsafe { - self.components.register_required_components_synced::( - requiree, - required, - constructor, - ) - } + unsafe { components.register_required_components::(requiree, required, constructor) } } /// Retrieves the [components info](ComponentInfoRef) for the given component type, if it exists.