Skip to content

Commit

Permalink
style: Handle the non-generic path earlier in the derive code.
Browse files Browse the repository at this point in the history
No need to build the match body if there are no generics. This should hopefully
save some work too.

Depends on D26289

Differential Revision: https://phabricator.services.mozilla.com/D26290
  • Loading branch information
emilio committed Apr 12, 2019
1 parent c3ab3f0 commit fc0dad2
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions components/style_derive/to_computed_value.rs
Expand Up @@ -30,6 +30,21 @@ pub fn derive_to_value(
// to this token stream, which should be the body of the impl block. // to this token stream, which should be the body of the impl block.
non_generic_implementation: impl FnOnce() -> Option<TokenStream>, non_generic_implementation: impl FnOnce() -> Option<TokenStream>,
) -> TokenStream { ) -> TokenStream {
let name = &input.ident;

if input.generics.type_params().next().is_none() {
if let Some(non_generic_implementation) = non_generic_implementation() {
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
return quote! {
impl #impl_generics #trait_path for #name #ty_generics
#where_clause
{
#non_generic_implementation
}
};
}
}

let mut where_clause = input.generics.where_clause.take(); let mut where_clause = input.generics.where_clause.take();
cg::propagate_clauses_to_output_type( cg::propagate_clauses_to_output_type(
&mut where_clause, &mut where_clause,
Expand Down Expand Up @@ -73,20 +88,7 @@ pub fn derive_to_value(
}; };


input.generics.where_clause = where_clause; input.generics.where_clause = where_clause;
let name = &input.ident;
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
if input.generics.type_params().next().is_none() {
if let Some(non_generic_implementation) = non_generic_implementation() {
return quote! {
impl #impl_generics #trait_path for #name #ty_generics
#where_clause
{
#non_generic_implementation
}
};
}
}

let computed_value_type = cg::fmap_trait_output( let computed_value_type = cg::fmap_trait_output(
&input, &input,
&trait_path, &trait_path,
Expand Down

0 comments on commit fc0dad2

Please sign in to comment.