Skip to content

Commit c3a386f

Browse files
committed
Fix review comments
1 parent 21d9170 commit c3a386f

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

crates/bevy_ecs/macros/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
118118
{
119119
if *is_bundle {
120120
field_component_ids.push(quote! {
121-
component_id.extend(<#field_type as #ecs_path::bundle::Bundle>::component_id(components));
121+
component_ids.extend(<#field_type as #ecs_path::bundle::Bundle>::component_ids(components));
122122
});
123123
field_get_components.push(quote! {
124124
self.#field.get_components(&mut func);
@@ -128,7 +128,7 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
128128
});
129129
} else {
130130
field_component_ids.push(quote! {
131-
component_id.push(components.get_or_insert_id::<#field_type>());
131+
component_ids.push(components.get_or_insert_id::<#field_type>());
132132
});
133133
field_get_components.push(quote! {
134134
func((&mut self.#field as *mut #field_type).cast::<u8>());
@@ -147,12 +147,12 @@ pub fn derive_bundle(input: TokenStream) -> TokenStream {
147147
TokenStream::from(quote! {
148148
/// SAFE: TypeInfo is returned in field-definition-order. [from_components] and [get_components] use field-definition-order
149149
unsafe impl #impl_generics #ecs_path::bundle::Bundle for #struct_name#ty_generics #where_clause {
150-
fn component_id(
150+
fn component_ids(
151151
components: &mut #ecs_path::component::Components,
152152
) -> Vec<#ecs_path::component::ComponentId> {
153-
let mut component_id = Vec::with_capacity(#field_len);
153+
let mut component_ids = Vec::with_capacity(#field_len);
154154
#(#field_component_ids)*
155-
component_id
155+
component_ids
156156
}
157157

158158
#[allow(unused_variables, unused_mut, non_snake_case)]

crates/bevy_ecs/src/bundle.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use std::{any::TypeId, collections::HashMap};
4444
/// [Bundle::component_id]
4545
pub unsafe trait Bundle: Send + Sync + 'static {
4646
/// Gets this [Bundle]'s component ids, in the order of this bundle's Components
47-
fn component_id(components: &mut Components) -> Vec<ComponentId>;
47+
fn component_ids(components: &mut Components) -> Vec<ComponentId>;
4848

4949
/// Calls `func`, which should return data for each component in the bundle, in the order of
5050
/// this bundle's Components
@@ -67,7 +67,7 @@ macro_rules! tuple_impl {
6767
/// SAFE: TypeInfo is returned in tuple-order. [Bundle::from_components] and [Bundle::get_components] use tuple-order
6868
unsafe impl<$($name: Component),*> Bundle for ($($name,)*) {
6969
#[allow(unused_variables)]
70-
fn component_id(components: &mut Components) -> Vec<ComponentId> {
70+
fn component_ids(components: &mut Components) -> Vec<ComponentId> {
7171
vec![$(components.get_or_insert_id::<$name>()),*]
7272
}
7373

@@ -206,11 +206,11 @@ impl Bundles {
206206
) -> &'a BundleInfo {
207207
let bundle_infos = &mut self.bundle_infos;
208208
let id = self.bundle_ids.entry(TypeId::of::<T>()).or_insert_with(|| {
209-
let component_id = T::component_id(components);
209+
let component_ids = T::component_ids(components);
210210
let id = BundleId(bundle_infos.len());
211211
// SAFE: T::component_id ensures info was created
212212
let bundle_info = unsafe {
213-
initialize_bundle(std::any::type_name::<T>(), &component_id, id, components)
213+
initialize_bundle(std::any::type_name::<T>(), component_ids, id, components)
214214
};
215215
bundle_infos.push(bundle_info);
216216
id
@@ -225,17 +225,15 @@ impl Bundles {
225225
/// `component_id` must be valid [ComponentId]'s
226226
unsafe fn initialize_bundle(
227227
bundle_type_name: &'static str,
228-
component_id: &[ComponentId],
228+
component_ids: Vec<ComponentId>,
229229
id: BundleId,
230230
components: &mut Components,
231231
) -> BundleInfo {
232-
let mut component_ids = Vec::new();
233232
let mut storage_types = Vec::new();
234233

235-
for &component_id in component_id {
234+
for &component_id in &component_ids {
236235
// SAFE: component_id exists and is therefore valid
237236
let component_info = components.get_info_unchecked(component_id);
238-
component_ids.push(component_id);
239237
storage_types.push(component_info.storage_type());
240238
}
241239

crates/bevy_ecs/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ mod tests {
115115
.unwrap();
116116

117117
assert_eq!(
118-
<Foo as Bundle>::component_id(world.components_mut()),
118+
<Foo as Bundle>::component_ids(world.components_mut()),
119119
vec![
120120
world.components_mut().get_or_insert_id::<&'static str>(),
121121
world.components_mut().get_or_insert_id::<i32>(),
@@ -151,7 +151,7 @@ mod tests {
151151
}
152152

153153
assert_eq!(
154-
<Nested as Bundle>::component_id(world.components_mut()),
154+
<Nested as Bundle>::component_ids(world.components_mut()),
155155
vec![
156156
world.components_mut().get_or_insert_id::<usize>(),
157157
world.components_mut().get_or_insert_id::<&'static str>(),

0 commit comments

Comments
 (0)