From c641a905dc2e95f507477d5363990bd8381aa0f6 Mon Sep 17 00:00:00 2001 From: David Sugar Date: Thu, 30 Dec 2021 20:08:40 +0000 Subject: [PATCH] StorageType parameter removed from ComponentDescriptor::new_resource (#3495) # Objective Remove the `StorageType` parameter from `ComponentDescriptor::new_resource` as discussed in #3361. - fixes #3361 ## Solution - Parameter removed. - Basic docs added. ## Note Left a [comment](https://github.com/bevyengine/bevy/issues/3361#issuecomment-996433346) about `SparseStorage` being the more reasonable choice. Co-authored-by: r4gus --- crates/bevy_ecs/src/component.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ecs/src/component.rs b/crates/bevy_ecs/src/component.rs index a38132fc4c435..92ade0560df57 100644 --- a/crates/bevy_ecs/src/component.rs +++ b/crates/bevy_ecs/src/component.rs @@ -194,10 +194,15 @@ impl ComponentDescriptor { } } - pub fn new_resource(storage_type: StorageType) -> Self { + /// Create a new `ComponentDescriptor` for a resource. + /// + /// The [`StorageType`] for resources is always [`TableStorage`]. + pub fn new_resource() -> Self { Self { name: std::any::type_name::().to_string(), - storage_type, + // PERF: `SparseStorage` may actually be a more + // reasonable choice as `storage_type` for resources. + storage_type: StorageType::Table, is_send_and_sync: true, type_id: Some(TypeId::of::()), layout: Layout::new::(), @@ -308,7 +313,7 @@ impl Components { // SAFE: The [`ComponentDescriptor`] matches the [`TypeId`] unsafe { self.get_or_insert_resource_with(TypeId::of::(), || { - ComponentDescriptor::new_resource::(StorageType::default()) + ComponentDescriptor::new_resource::() }) } }