Bug 1542179 - Handle the non-generic path earlier in the derive code. r=heycam
authorEmilio Cobos Álvarez <emilio@crisal.io>
Tue, 09 Apr 2019 01:48:18 +0000
changeset 468547 dfef5e9b459d20352443637a47b24fe9f26070e4
parent 468546 7f7030e4c60dd6e44c811c2969c158095cba4536
child 468548 ae6b824bbe75f21fba58d990de702d25799ce200
push id112733
push usercsabou@mozilla.com
push dateTue, 09 Apr 2019 16:30:22 +0000
treeherdermozilla-inbound@e14dba56bbfd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1542179
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1542179 - Handle the non-generic path earlier in the derive code. r=heycam 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
servo/components/style_derive/to_computed_value.rs
--- a/servo/components/style_derive/to_computed_value.rs
+++ b/servo/components/style_derive/to_computed_value.rs
@@ -25,16 +25,31 @@ pub fn derive_to_value(
     // fn to_function_syntax(foobar) -> Baz {
     //     #second_arg
     // }
     mut trait_impl: impl FnMut(TokenStream, TokenStream) -> TokenStream,
     // if this is provided, the derive for non-generic types will be simplified
     // to this token stream, which should be the body of the impl block.
     non_generic_implementation: impl FnOnce() -> Option<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();
     cg::propagate_clauses_to_output_type(
         &mut where_clause,
         &input.generics,
         &trait_path,
         &output_type_name,
     );
     let (to_body, from_body) = {
@@ -68,30 +83,17 @@ pub fn derive_to_value(
         let from_body = cg::fmap_match(&input, bind_style, |binding| {
             call_from(&binding)
         });
 
         (to_body, from_body)
     };
 
     input.generics.where_clause = where_clause;
-    let name = &input.ident;
     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(
         &input,
         &trait_path,
         &output_type_name,
     );
 
     let impl_ = trait_impl(from_body, to_body);