Skip to content

Commit 607f9f2

Browse files
authored
Avoid unnecessary ReflectMeta arguments (#19919)
# Objective `WhereClauseOption` contains a reference to a `ReflectMeta`. Oddly enough, a bunch of functions that take a `WhereClauseOption` argument also take a `ReflectMeta` reference argument, which is exactly the same as the reference in the `WhereClauseOption`. ## Solution This commit removes the redundant `ReflectMeta` argument from these functions. This requires adding a `WhereClauseOption::meta` getter method. ## Testing `cargo run -p ci`
1 parent ee18073 commit 607f9f2

File tree

13 files changed

+31
-56
lines changed

13 files changed

+31
-56
lines changed

crates/bevy_reflect/derive/src/derive_data.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,6 @@ impl<'a> ReflectMeta<'a> {
482482
where_clause_options: &WhereClauseOptions,
483483
) -> proc_macro2::TokenStream {
484484
crate::registration::impl_get_type_registration(
485-
self,
486485
where_clause_options,
487486
None,
488487
Option::<core::iter::Empty<&Type>>::None,
@@ -599,7 +598,6 @@ impl<'a> ReflectStruct<'a> {
599598
where_clause_options: &WhereClauseOptions,
600599
) -> proc_macro2::TokenStream {
601600
crate::registration::impl_get_type_registration(
602-
self.meta(),
603601
where_clause_options,
604602
self.serialization_data(),
605603
Some(self.active_types().iter()),
@@ -880,7 +878,6 @@ impl<'a> ReflectEnum<'a> {
880878
where_clause_options: &WhereClauseOptions,
881879
) -> proc_macro2::TokenStream {
882880
crate::registration::impl_get_type_registration(
883-
self.meta(),
884881
where_clause_options,
885882
None,
886883
Some(self.active_fields().map(StructField::reflected_type)),

crates/bevy_reflect/derive/src/impls/common.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ use quote::quote;
44

55
use crate::{derive_data::ReflectMeta, where_clause_options::WhereClauseOptions};
66

7-
pub fn impl_full_reflect(
8-
meta: &ReflectMeta,
9-
where_clause_options: &WhereClauseOptions,
10-
) -> proc_macro2::TokenStream {
7+
pub fn impl_full_reflect(where_clause_options: &WhereClauseOptions) -> proc_macro2::TokenStream {
8+
let meta = where_clause_options.meta();
119
let bevy_reflect_path = meta.bevy_reflect_path();
1210
let type_path = meta.type_path();
1311

crates/bevy_reflect/derive/src/impls/enums.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
3636
let ref_index = Ident::new("__index_param", Span::call_site());
3737
let ref_value = Ident::new("__value_param", Span::call_site());
3838

39-
let where_clause_options = reflect_enum.where_clause_options();
40-
4139
let EnumImpls {
4240
enum_field,
4341
enum_field_mut,
@@ -57,14 +55,11 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
5755
..
5856
} = TryApplyVariantBuilder::new(reflect_enum).build(&ref_value);
5957

60-
let typed_impl = impl_typed(
61-
reflect_enum.meta(),
62-
&where_clause_options,
63-
reflect_enum.to_info_tokens(),
64-
);
58+
let where_clause_options = reflect_enum.where_clause_options();
59+
let typed_impl = impl_typed(&where_clause_options, reflect_enum.to_info_tokens());
6560

6661
let type_path_impl = impl_type_path(reflect_enum.meta());
67-
let full_reflect_impl = impl_full_reflect(reflect_enum.meta(), &where_clause_options);
62+
let full_reflect_impl = impl_full_reflect(&where_clause_options);
6863
let common_methods = common_partial_reflect_methods(
6964
reflect_enum.meta(),
7065
|| Some(quote!(#bevy_reflect_path::enum_partial_eq)),
@@ -75,8 +70,7 @@ pub(crate) fn impl_enum(reflect_enum: &ReflectEnum) -> proc_macro2::TokenStream
7570
#[cfg(not(feature = "functions"))]
7671
let function_impls = None::<proc_macro2::TokenStream>;
7772
#[cfg(feature = "functions")]
78-
let function_impls =
79-
crate::impls::impl_function_traits(reflect_enum.meta(), &where_clause_options);
73+
let function_impls = crate::impls::impl_function_traits(&where_clause_options);
8074

8175
let get_type_registration_impl = reflect_enum.get_type_registration(&where_clause_options);
8276

crates/bevy_reflect/derive/src/impls/func/from_arg.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use crate::{derive_data::ReflectMeta, where_clause_options::WhereClauseOptions};
1+
use crate::where_clause_options::WhereClauseOptions;
22
use bevy_macro_utils::fq_std::FQResult;
33
use quote::quote;
44

5-
pub(crate) fn impl_from_arg(
6-
meta: &ReflectMeta,
7-
where_clause_options: &WhereClauseOptions,
8-
) -> proc_macro2::TokenStream {
5+
pub(crate) fn impl_from_arg(where_clause_options: &WhereClauseOptions) -> proc_macro2::TokenStream {
6+
let meta = where_clause_options.meta();
97
let bevy_reflect = meta.bevy_reflect_path();
108
let type_path = meta.type_path();
119

crates/bevy_reflect/derive/src/impls/func/function_impls.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::{
2-
derive_data::ReflectMeta,
32
impls::func::{
43
from_arg::impl_from_arg, get_ownership::impl_get_ownership, into_return::impl_into_return,
54
},
@@ -8,12 +7,11 @@ use crate::{
87
use quote::quote;
98

109
pub(crate) fn impl_function_traits(
11-
meta: &ReflectMeta,
1210
where_clause_options: &WhereClauseOptions,
1311
) -> proc_macro2::TokenStream {
14-
let get_ownership = impl_get_ownership(meta, where_clause_options);
15-
let from_arg = impl_from_arg(meta, where_clause_options);
16-
let into_return = impl_into_return(meta, where_clause_options);
12+
let get_ownership = impl_get_ownership(where_clause_options);
13+
let from_arg = impl_from_arg(where_clause_options);
14+
let into_return = impl_into_return(where_clause_options);
1715

1816
quote! {
1917
#get_ownership

crates/bevy_reflect/derive/src/impls/func/get_ownership.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{derive_data::ReflectMeta, where_clause_options::WhereClauseOptions};
1+
use crate::where_clause_options::WhereClauseOptions;
22
use quote::quote;
33

44
pub(crate) fn impl_get_ownership(
5-
meta: &ReflectMeta,
65
where_clause_options: &WhereClauseOptions,
76
) -> proc_macro2::TokenStream {
7+
let meta = where_clause_options.meta();
88
let bevy_reflect = meta.bevy_reflect_path();
99
let type_path = meta.type_path();
1010

crates/bevy_reflect/derive/src/impls/func/into_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::{derive_data::ReflectMeta, where_clause_options::WhereClauseOptions};
1+
use crate::where_clause_options::WhereClauseOptions;
22
use quote::quote;
33

44
pub(crate) fn impl_into_return(
5-
meta: &ReflectMeta,
65
where_clause_options: &WhereClauseOptions,
76
) -> proc_macro2::TokenStream {
7+
let meta = where_clause_options.meta();
88
let bevy_reflect = meta.bevy_reflect_path();
99
let type_path = meta.type_path();
1010

crates/bevy_reflect/derive/src/impls/opaque.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream {
2121

2222
let where_clause_options = WhereClauseOptions::new(meta);
2323
let typed_impl = impl_typed(
24-
meta,
2524
&where_clause_options,
2625
quote! {
2726
let info = #bevy_reflect_path::OpaqueInfo::new::<Self>() #with_docs;
@@ -30,7 +29,7 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream {
3029
);
3130

3231
let type_path_impl = impl_type_path(meta);
33-
let full_reflect_impl = impl_full_reflect(meta, &where_clause_options);
32+
let full_reflect_impl = impl_full_reflect(&where_clause_options);
3433
let common_methods = common_partial_reflect_methods(meta, || None, || None);
3534
let clone_fn = meta.attrs().get_clone_impl(bevy_reflect_path);
3635

@@ -54,7 +53,7 @@ pub(crate) fn impl_opaque(meta: &ReflectMeta) -> proc_macro2::TokenStream {
5453
#[cfg(not(feature = "functions"))]
5554
let function_impls = None::<proc_macro2::TokenStream>;
5655
#[cfg(feature = "functions")]
57-
let function_impls = crate::impls::impl_function_traits(meta, &where_clause_options);
56+
let function_impls = crate::impls::impl_function_traits(&where_clause_options);
5857

5958
let (impl_generics, ty_generics, where_clause) = type_path.generics().split_for_impl();
6059
let where_reflect_clause = where_clause_options.extend_where_clause(where_clause);

crates/bevy_reflect/derive/src/impls/structs.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,10 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS
3434
} = FieldAccessors::new(reflect_struct);
3535

3636
let where_clause_options = reflect_struct.where_clause_options();
37-
let typed_impl = impl_typed(
38-
reflect_struct.meta(),
39-
&where_clause_options,
40-
reflect_struct.to_info_tokens(false),
41-
);
37+
let typed_impl = impl_typed(&where_clause_options, reflect_struct.to_info_tokens(false));
4238

4339
let type_path_impl = impl_type_path(reflect_struct.meta());
44-
let full_reflect_impl = impl_full_reflect(reflect_struct.meta(), &where_clause_options);
40+
let full_reflect_impl = impl_full_reflect(&where_clause_options);
4541
let common_methods = common_partial_reflect_methods(
4642
reflect_struct.meta(),
4743
|| Some(quote!(#bevy_reflect_path::struct_partial_eq)),
@@ -52,8 +48,7 @@ pub(crate) fn impl_struct(reflect_struct: &ReflectStruct) -> proc_macro2::TokenS
5248
#[cfg(not(feature = "functions"))]
5349
let function_impls = None::<proc_macro2::TokenStream>;
5450
#[cfg(feature = "functions")]
55-
let function_impls =
56-
crate::impls::impl_function_traits(reflect_struct.meta(), &where_clause_options);
51+
let function_impls = crate::impls::impl_function_traits(&where_clause_options);
5752

5853
let get_type_registration_impl = reflect_struct.get_type_registration(&where_clause_options);
5954

crates/bevy_reflect/derive/src/impls/tuple_structs.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2::
2424
let where_clause_options = reflect_struct.where_clause_options();
2525
let get_type_registration_impl = reflect_struct.get_type_registration(&where_clause_options);
2626

27-
let typed_impl = impl_typed(
28-
reflect_struct.meta(),
29-
&where_clause_options,
30-
reflect_struct.to_info_tokens(true),
31-
);
27+
let typed_impl = impl_typed(&where_clause_options, reflect_struct.to_info_tokens(true));
3228

3329
let type_path_impl = impl_type_path(reflect_struct.meta());
34-
let full_reflect_impl = impl_full_reflect(reflect_struct.meta(), &where_clause_options);
30+
let full_reflect_impl = impl_full_reflect(&where_clause_options);
3531
let common_methods = common_partial_reflect_methods(
3632
reflect_struct.meta(),
3733
|| Some(quote!(#bevy_reflect_path::tuple_struct_partial_eq)),
@@ -42,8 +38,7 @@ pub(crate) fn impl_tuple_struct(reflect_struct: &ReflectStruct) -> proc_macro2::
4238
#[cfg(not(feature = "functions"))]
4339
let function_impls = None::<proc_macro2::TokenStream>;
4440
#[cfg(feature = "functions")]
45-
let function_impls =
46-
crate::impls::impl_function_traits(reflect_struct.meta(), &where_clause_options);
41+
let function_impls = crate::impls::impl_function_traits(&where_clause_options);
4742

4843
let (impl_generics, ty_generics, where_clause) = reflect_struct
4944
.meta()

0 commit comments

Comments
 (0)