This commit is contained in:
Urben1680 2025-07-15 21:36:41 +02:00
parent 177ecbe3f2
commit 0e4643c2b9
2 changed files with 3 additions and 45 deletions

View File

@ -166,8 +166,7 @@ impl BundleInfo {
match component_to_containing_bundles.get_mut(component.index()) {
Some(bundles) => bundles.push(self.id),
None => {
component_to_containing_bundles
.resize_with(component.index() + 1, || Vec::new());
component_to_containing_bundles.resize_with(component.index() + 1, Vec::new);
*component_to_containing_bundles.last_mut().unwrap() = vec![self.id];
}
}
@ -468,21 +467,6 @@ impl Bundles {
self.bundle_infos.iter()
}
/// Iterate over [`BundleInfo`] containing `component`, either explicitly or as required.
pub(crate) fn iter_containing(
&self,
component: ComponentId,
) -> impl Iterator<Item = &BundleInfo> {
self.component_to_containing_bundles
.get(component.index())
.into_iter()
.flatten()
.map(|id| {
// SAFETY: component_to_containing_bundles contains only valid ids
unsafe { self.bundle_infos.get(id.index()).debug_checked_unwrap() }
})
}
/// Gets the metadata associated with a specific type of bundle.
/// Returns `None` if the bundle is not registered with the world.
#[inline]
@ -535,7 +519,7 @@ impl Bundles {
if let Some(id) = self.contributed_bundle_ids.get(&TypeId::of::<T>()).cloned() {
id
} else {
let explicit_bundle_id = self.register_info::<T>(components, storages);
let explicit_bundle_id: BundleId = self.register_info::<T>(components, storages);
// SAFETY: reading from `explicit_bundle_id` and creating new bundle in same time. Its valid because bundle hashmap allow this
let id = unsafe {
let (ptr, len) = {

View File

@ -146,7 +146,7 @@ pub struct HotPatched;
#[cfg(test)]
mod tests {
use crate::{
bundle::{Bundle, BundleId, BundleInfo},
bundle::Bundle,
change_detection::Ref,
component::{Component, ComponentId, RequiredComponents, RequiredComponentsError},
entity::{Entity, EntityMapper},
@ -2595,14 +2595,6 @@ mod tests {
#[derive(Component, Default)]
struct E;
fn bundle_containing(world: &World, component: ComponentId) -> Option<BundleId> {
world
.bundles()
.iter_containing(component)
.next()
.map(BundleInfo::id)
}
let mut world = World::new();
let a_id = world.register_component::<A>();
@ -2621,12 +2613,6 @@ mod tests {
assert!(!contributed.contains(&d_id));
assert!(!contributed.contains(&e_id));
assert_eq!(bundle_containing(&world, a_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, b_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, c_id), None);
assert_eq!(bundle_containing(&world, d_id), None);
assert_eq!(bundle_containing(&world, e_id), None);
// check if registration succeeds
world.register_required_components::<B, C>();
let bundle = world.bundles().get(bundle_id).unwrap();
@ -2638,12 +2624,6 @@ mod tests {
assert!(contributed.contains(&d_id));
assert!(!contributed.contains(&e_id));
assert_eq!(bundle_containing(&world, a_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, b_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, c_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, d_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, e_id), None);
// check if another registration can be associated to the bundle using the previously registered component
world.register_required_components::<D, E>();
let bundle = world.bundles().get(bundle_id).unwrap();
@ -2654,12 +2634,6 @@ mod tests {
assert!(contributed.contains(&c_id));
assert!(contributed.contains(&d_id));
assert!(contributed.contains(&e_id));
assert_eq!(bundle_containing(&world, a_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, b_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, c_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, d_id), Some(bundle_id));
assert_eq!(bundle_containing(&world, e_id), Some(bundle_id));
}
#[test]